Question: Write an application that asks a user to type an even number or the sentinel value 999 to stop. When the user types an even

Write an application that asks a user to type an even number or the sentinel value 999 to stop. When the user types an even number, display the message Good job! and then ask for another input. When the user types an odd number, display an error message and then ask for another input. For example, if 101 is input, the error message should be:

 

When the user types the sentinel value 999, end the program.

Says Im failing the odd and any number test.

Here is my code

import java.util.*; public class EvenEntryLoop{ public static void main(String args[]){ int number; Scanner in = new Scanner(System.in); while(true){ System.out.print("Enter a number: "); number = in.nextInt(); if(number == 999) break; if(number % 2 == 0) System.out.println("Good job!"); else System.out.println("Error!! Number is not an even number!"); } } }

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!