Question: Java programming: The feedback I received: remove want to continue question Original question: Program 1 Write a program as follows: prompt the user to enter

Java programming:

The feedback I received: "remove want to continue question"

Original question:

Program 1

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 by throwing an exception.

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

_______________________________________________________________

My Code:

import java.util.*;

public class Program1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in); byte number;

String select;

while (true) { int j = 1; System.out.println("Sample Run " + j);

System.out.print(" Enter a positive byte value ");

try { number = input.nextByte();

if (number >= 32 && number <= 123) { System.out.print(" In ASCII, that is character " + (char) number); } else { System.out.print("Bad input "); }

} catch (InputMismatchException ex) { System.out.print("Bad input ");

}

System.out.print(" want to continue (y/n) "); select = input.next();

if (select == "y" || select == "Y") { j++; continue; } else {

break; } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!