Hello, I\'d like to have someone solve this problem for me so I can make sure I\
ID: 3908931 • Letter: H
Question
Hello, I'd like to have someone solve this problem for me so I can make sure I'm doing it right, the language is in java:
Question 14 10 pts Write code to read a positive number in from the user and store the variable in userNuim If the user enters a negative number or zero, ask them to try again. Continue asking until the user enters a positive number. This code would go inside the main method. Use a loop.Explanation / Answer
import java.util.Scanner; public class ReadPositiveNumber { public static void main(String[] args) { Scanner in = new Scanner(System.in); int userNuim; while (true) { System.out.print("Enter a positive number: "); userNuim = in.nextInt(); if(userNuim > 0) { break; } System.out.println("Try again!"); } System.out.println("You entered " + userNuim); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.