Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

Students also viewed these Databases questions