Question: 31.12 Ch. 04 Validate Input Values (for loop, if) [Java needed] Write a program that asks the user for three int values n, a, and

31.12 Ch. 04 Validate Input Values (for loop, if) [Java needed]

Write a program that asks the user for three int values n, a, and b, where a < b. The program will then ask the user to enter n integer values. For each value v, the program prints a message to indicate it is valid if the value is divisible by a or b. Otherwise, print a message to indicate that the value is not valid.

For example as an output example, see the one shown between the two lines next:

Enter an integer greater than zero: 6

Enter two values a and b, where a < b: 3 7

Enter 6 values to check.

Enter a value: 2 value 2 is not valid.

Enter a value: 3 value 3 is valid.

Enter a value: 4 value 4 is not valid.

Enter a value: 5 value 5 is not valid.

Enter a value: 6 value 6 is valid.

Enter a value: 7 value 7 is valid.

Requirements:

  • Use class constant IN for a Scanner
  • Able to solve the problem is the user entered a and b where b is smaller than a
  • Allow the n numbers to be double type

Please note that in the example shown above:

  • You should show the message to ask for the values before your read the value from the keyboard (the Scanner method call).
  • The values shown in bold are the values that the user input
  • The output in Zybooks will differ where the input will not be shown where it was read. In other words, the values in bold will not be shown in your output and it will not change line either.
  • All the other parts of the output should match.

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!