Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Often it is necessary to validate data input by the user and repeat the request for the data in the case where the input

image text in transcribed imageimageimageimageimage

Often it is necessary to validate data input by the user and repeat the request for the data in the case where the input of the user is not valid. This can be done by using a do loop, while loop, or for loop See the Lab04 04 example Assign 4.1(Lab04_01) Make a program from the following checkpoint if you cannot do it see solution. Checkpoint 4.1 What will the following program segments display? a) x = 2; y = x++; System.out.println(y); b) x = 2; System.out.println(x++); c) x = 2; System.out.println(--x); d) x = 8; y = x--; System.out.println(y); Solution: } Make a program from the following checkpoint if you cannot do it see Solution. 4.4 Write an input validation loop that asks the user to enter a number in the range of 10 through 24. public class Lab04_01 public static void main(String[] args) { { int x; Solution: int y; x-2; yx++; System.out.println(y); x = 2; System.out.println(x++); x=2; System.out.println(--x); x-8; y-x--; System.out.println(y); public class Lab4_04 //program name is case sensitive { public static void main(String[] args) { int num=15; while (num>=10 &&num of 6 C ZOOM + import java.util.Scanner; public class Lab4_04x //program name is case sensitive { public static void main(String[] args) { System.out.println("Enter a number between 10 to 24"); Scanner inNum = new Scanner(System.in); int num-inNum.nextInt(); while (num>=10 &&num of 6 C ZOOM + import java.util.Scanner; public class Assign4_5 { { public static void main(String[] args) Scanner keyboard = new Scanner(System.in); System.out.print("Enter a Y or y: "); String str keyboard.nextLine(); // read the first line char ch1 str.charAt(0); // read the first character of str string. while(chl='Y' || ch =='y') L// Compar the ch1 with y or Y {{//if expression is true, print the blow line and break the loop System.out.println("You enter Y or y "+str); break; } Assign4_5.java Compile Messages GRASP Messages Run I/O Interactions Enter a Y or y: y End You enter Y or y, you enter y Clear ----jGRASP: operation complete. import java.util.Scanner; public class Assign4_5 public static void main(String[] args) { { Scanner keyboard = new Scanner(System.in); System.out.print ("Enter a Y or y: "); String str = keyboard.nextLine(); // read the first line from input char ch1 = str.charAt(0); character of str string. // read the first the chl with while ( ch1=='Y' || ch1 =='y') // compare y or Y {//if expression is true, print the blow line and break the loop System.out.println("You enter Y or y "+str); break; } Page < 4 > of 6 C ZOOM + } Optimal: If you have extra time, please practice the following. no credit If you have extra time use the Scanner keyboard= new Scanner(System.in); by declare and using the import java.util.Scanner; Assin4.1 to 4.6 using Scanner import to read in from keyboard by the API import java.util.Scanner; on the header file Inside the main usage. int num=0; Scanner keyboard= new Scanner(System.in); System.out.print("Enter a number between 10to 28: "); num = keyboard.nextInt(); Here is complete program screenshot, the checkpoint 4.1 to 4.6: Page < 5 > of 6 C ZOOM + import java.util.Scanner; public class Assig4_1To_4_6 public static void main(String[] args) { { int x =2; int y =x++; System.out.println(y); x=2; System.out.println(x++); x=2; System.out.println(--x); x=8; y =x--; System.out.println(y); int num=1; Scanner keyboard= new Scanner(System.in); System.out.print("Enter a number betweeb 10to 28: "); num = keyboard.nextInt(); while(num >=10 && num of 6 C ZOOM +

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

Lets break it down step by step Understanding the Checkpoints a x 2 y x Systemoutprintlny In this se... 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

Step: 3

blur-text-image

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

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions

Question

Explain what trade secrets protect and how they may be infringed.

Answered: 1 week ago

Question

=+d. What is the expected time for completing both tasks?

Answered: 1 week ago