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");
}
}
}
Step-by-step 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