Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this Java Programming assignment: Write a program as follows: p

ID: 3908913 • Letter: I

Question

I need help with this Java Programming assignment:

Write a program as follows:

prompt the user to enter a positive value of type byte.

cast this input first to type int and then to type char.

if the char is a printable ASCII character (from 32 to 123 ), display it.

if the user's input is bad, the program should end gracefully with an error message.

Sample Run 1

Enter a positive byte value 67

In ASCII, that is character C

Sample Run 2

Enter a positive byte value 300

Bad input. Run program again

Sample Run 3

Enter a positive byte value twelve

Bad input. Run program again

Explanation / Answer

import java.util.Scanner; public class PrintAscii { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = 0; try { System.out.print("Enter a positive byte value "); num = Integer.parseInt(in.next()); } catch (Exception e) { } if(num >= 32 && num