Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions