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 && numRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.