Question

In: Computer Science

Write an application that asks a user to type an even number or the sentinel value...

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, "x is not an even number", and then ask for another input. When the user types the sentinel value 999, end the program.

Solutions

Expert Solution

In the code, firstly user will ask to enter the number

Then, we have used while loop till the enetered number becomes 999

If number is not 999 , then control will move inside the loop and check whether if it is even or odd

If the number is even , which is checked with statement num%2==0 , control will move inside the If statement and print "Good Job" in console

If number is odd, control will move inside Else statement and print "x is not an even number" in console

And then again , ask user to enter the number , if enetered number is 999 , control will exit the loop and terminate the program

If number entered is not 999 , again control will move inside the loop

Please find the below code in JAVA:

import java.util.*;

public class Main
{
   public static void main(String[] args) {
   Scanner scr=new Scanner(System.in);
  
  
System.out.println("Enter even number or 999 sentinel");
int number=scr.nextInt();
while (number!=999){
  
if(number%2==0){
System.out.println("Good Job");
}
else
{
System.out.println("x is not a even number");
}
System.out.println("Enter even number or 999 sentinel");
number=scr.nextInt();
}
}
}

Please find the output screnshot:


Related Solutions

Write C++ void function called averageTemperature() that asks the user to enter integers with a sentinel...
Write C++ void function called averageTemperature() that asks the user to enter integers with a sentinel value of -999 to stop entering numbers. Then average the numbers and print the average. You will need an int acculumator for the temperatures and an int acculumator for the number of temperatures entered. Use the accumulators to calculate the average which will need to be a decimal number. Call the function from the main() function.
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
1) Write Java application that asks the user to enter the cost of each apple and...
1) Write Java application that asks the user to enter the cost of each apple and number of apples bought. Application obtains the values from the user and prints the total cost of apples. 2) Write a java application that computes the cost of 135 apples, where the cost of each apple is $0.30. 3)Write a java application that prepares the Stationery List. Various entries in the table must be obtained from the user. Display the Stationary list in the...
Write a program in Java that first asks the user to type in today's price of...
Write a program in Java that first asks the user to type in today's price of one dollar in Japanese yen, then reads U.S. dollar values and converts each to yen. Use 0 as a sentinel to denote the end of dollar input. THEN the program reads a sequence of yen amounts and converts them to dollars. The second sequence is terminated by another zero value.
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
Write a java program that asks the user for a number n and gives them the...
Write a java program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n. Example of running this program: Enter an integer number n: __7________ Enter Sum or Product: __Sum__________________________________ Program output: Sum of 1 ... 7 Sum or Product: Sum Sum = 28 Now second sample of second execution Enter an integer number n: __5__________________________________ Enter Sum or Product: __Product__________________________________ Program output:  Product of 1...
write a program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
In Java: Write a program that generates a random number and asks the user to guess...
In Java: Write a program that generates a random number and asks the user to guess the number and keeps track of how many guesses it took If the user input is negative or zero then the loop must stop reading further inputs and display how many guesses they used If they guess the correct number display a message telling them they got it and exit the program If they guess the wrong number (but still a legal guess) you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT