Question
Java Program: Create a java program that allows the user to enter a negative or positive integer as many times as the user wants. If
Java Program:
Create a java program that allows the user to enter a negative or positive integer as many times as the user wants. If the user enters a negative integer then print the number and a message that says it's negative; otherwise, print the number and a message that says it's positive; otherwise, print a message that zero is neither negative or positive. You'll use a sentinel-controlled while loop, so ask the user whether he/she wants to enter an integer before entering the while loop. You'll have to ask the same question again at the end of the while loop. Save the program as WhileIfElse.java. Line advance at the beginning of a prompt. Line advance at the beginning and end of a message. Your spacing is to follow the Java Style Guide.
Instructions: Create a program that allows the user to enter a negative or positive integer as many times as the user wants. If the user enters a negative integer then print the number and a message that says it's negative, otherwise, print the number and a message that says it's positive; otherwise, print a message that zero is neither negative or positive. You'll use a sentinel-controlled while loop, so ask the user whether he/she wants to enter an integer before entering the while loop. You'll have to ask the same question again at the end of the while loop. Save the program as WhilelfE/se.java. Line advance at the beginning of a prompt. Line advance at the beginning and end of a message. Your spacing is to follow the Java Style Guide. //import statement I/class header //Begin class scope //Method header for main I/Begin method scope. 1/Declare input object for Scanner. //Declare variable called entry initialized to zero. 1/Declare variable called response initialized to blank space. I/Prompt "Do you want to enter an integer? Y or N: " //Store value in correct variable. 1/while header that tests uppercase in response I/Begin scope for while. 1/Prompt "Please enter an integer: 1/Store value in correct variable. //Clear buffer. I/Test if entry is greater than 0 //Begin if scope. //Print the number with a message that is positive, e.g., "3 is positive." //End if scope. //The option in a double-selection structure to handle if condition when false. //Begin option scope. //Test if entry is less than 0. //Begin nested if scope 1/Print the number with a message that is negative, e.g., "-3 is negative." //End nested if scope. //The option in a double-selection structure to handle nested if condition when false. //Beain nested option scope 1/Print "O is neither positive or negative." 1/End nested option scope. //End option scope. l/Prompt "Do you want to enter another integer? Y or N" 1/Store value in correct variable. I/End while scope //Exit program //End main method scope //End class scopeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started