Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Integer userNumber is read from input. Write a while loop that iterates until userNumber is negative. At each iteration: Update integer outputVal as follows: If
Integer userNumber is read from input. Write a while loop that iterates until userNumber is negative. At each iteration: Update integer outputVal as follows: If userNumber is even, output "lose" and do not update outputVal. Otherwise, output "win" and increment outputVal. Then, read an integer from input into variable userNumber. End each output with a newline. Ex: If the input is 2 6 5 -5, then the output is: lose lose win Output value is 1 Note: x % 2 == 0 returns true if x is even.
In Java (Zybooks) please
Integer userNumber is read from input. Write a while loop that iterates until userNumber is negative. At each iteration: - Update integer outputVal as follows: - If userNumber is even, output "lose" and do not update outputVal. - Otherwise, output "win" and increment outputVal. - Then, read an integer from input into variable userNumber. End each output with a newline. Ex: If the input is 2655, then the output is: lose lose win Output value is 1 Note: x%2==0 returns true if x is even. \begin{tabular}{l|l} 1 & import java.util. Scanner; \\ 2 & \\ 3 & public class ResultCalculator \{ \\ 4 & public static void main(String[] args) \{ \\ 5 & Scanner scnr = new Scanner(System. in); \\ 6 & int userNumber; \\ 7 & int outputVal; \\ 8 & \\ 9 & outputVal =0; \\ 10 & userNumber = scnr.nextInt(); \\ 11 & \\ 12 & Y* Your code goes here */ \\ 13 & \\ 14 & System.out.println("Output value is " + outputVal); \\ 15 & \} \end{tabular}Step 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