Instructions Write a program that asks the user for a number. If the number is between 1 and 255, the program outputs the corres
ponding ASCII character. If it is outside of that range, the program outputs Out of range.
1 answer:
Answer:
import java.util.Scanner;
public class num5 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a number between 1 -255");
int num = in.nextInt();
if(num >= 1 && num<=255){
char c = (char)num;
System.out.println("The ASCII Value of "+num+" is "+c);
}
else{
System.out.println("Out of range");
}
}
}
Explanation:
- Use the scanner class to receive a number from the user save in a variable num
- Use if statement to ensure the number is within the valid range num >= 1 && num<=255
- Convert the number to the ASCII equivalent by casting it to char data type
- Output the number and the ASCII equivalent
- if num was out of range, print Out of range
You might be interested in
Answer: Dark background and light text.
Explanation:
Assuming when you mean by "light text", you mean by white text. This should be able to be readable by users visiting the site.
Yes it would take a second or todo
num = int(input("Enter a number: "))
i = 2
while num > 1:
if num % i == 0:
num = num / i
print(i, end=" ")
i = 2
i += 1
I hope this helps!
Carlos Should use a Security Camera to keep track of his physical hardware. Carlos can then use a computer to monitor the security cameras.