Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote