Question: Integer userIn is read from input. Write a while loop that iterates until userIn is negative. In each iteration: Integer userIn is read from input.

Integer userIn is read from input. Write a while loop that iterates until userIn is negative. In each iteration: Integer userIn is read from input. Write a while loop that iterates until userIn is negative. In each iteration:
Update integer finalNum as follows:
If userIn is divisible by 5, output "win" and increment finalNum.
Otherwise, output "lose" and do not update finalNum.
Then, read the next integer from input into variable userln.
End each output with a newline.
Click here for example
Ex: If the input is 15,5,11-9, then the output is:
win
win
lose
Einal number is 2
Note: x%5==0 returns true if x is divisible by 5. Scanner scnr = new Scanner(System.in);int finalNum;userIn = scnr.nextInt();if (userIn %5==0){} else { finalNum++;userIn = scnr.nextInt();
}
Update integer finalNum as follows:
If userIn is divisible by 5, output "win" and increment finalNum.
Otherwise, output "lose" and do not update finalNum.
Then, read the next integer from input into variable userIn.
End each output with a newline.
Click here for example
Ex: If the input is 15511-9, then the output is:
win
win
lose
Final number is 2
Note: x %5==0 returns true if x is divisible by 5.
everything is right but can't get the final number is 2
 Integer userIn is read from input. Write a while loop that

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!