Help me modify my MaxSentinel Java Program(Attached image & Pasted Java Code) into a new program called MaximumSent... 1. Check for valid first entry. Then allow the user to enter as many numbers as desired. 2. If invalid number entered, print "Invalid entry." Prompt the user again until a valid number is entered. 3. Once -1 is entered, program stops and prints the largest number entered. Submit final code. JAVA CODE for MaxSentinel, has been pasted below: (also view attached images) import java.util.Scanner; public class MaxSentinel { public static void main(String[] args) { Scanner input=new Scanner(System.in); int num=0,max=-1; System.out.print("Enter positive integers(-1 to stop):"); num=input.nextInt(); while(num!=-1) { if(num>max) max=num; System.out.print("Enter positive integers(-1 to stop):"); num=input.nextInt(); } System.out.println("Largest number: "+max); } }
Help me modify my MaxSentinel Java
1. Check for valid first entry. Then allow the user to enter as many numbers as desired.
2. If invalid number entered, print "Invalid entry." Prompt the user again until a valid number is entered.
3. Once -1 is entered, program stops and prints the largest number entered.
Submit final code.
JAVA CODE for MaxSentinel, has been pasted below: (also view attached images)
import java.util.Scanner;
public class MaxSentinel
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int num=0,max=-1;
System.out.print("Enter positive integers(-1 to stop):");
num=input.nextInt();
while(num!=-1)
{
if(num>max)
max=num;
System.out.print("Enter positive integers(-1 to stop):");
num=input.nextInt();
}
System.out.println("Largest number: "+max);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images