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

![Project Name: MaxSentinel
1 import java.util.Scanner;
2
m & in 60 MISC98
3
4- {
5▾ public static void main(String[] args) {
Scanner input-new Scanner(System.in);
7
10
11 -
نانا
12
13
14
15
16
17
public class MaxSentinel
18
19
20
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);
}](https://content.bartleby.com/qna-images/question/6792dcb9-c6e0-4340-91fc-8edf4e069a95/a057ae66-c183-43c6-80d1-392da4ff2253/ygexae_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 3 images

- Java codearrow_forward1. Write Java code to repeatedly print each single digit between 1 and 9 the number of times based upon its numeric value. Thus, you would get a triangle of the shape below where 1 prints once, 2 twice . and 9 prints 9 times. 1 22 333 4444 55555 666666 7777777 88888888 999999999arrow_forwardIn Java 8, I want the program to capture the current year and compare it to an input value. Specifically, the user is asked to enter the last two digits of a year that will be output. If those two digits are greater than the last two digits of the current year, the program will print to console a “19” before the two digits the user inputted. If the two digits that the use input are less than or equal to the last two digits of the current year, the program will print to the console a “20” before the two digits the user inputted. For instance, if the current year is 2023, and the user input the integer number “74”, the program would output to the console “1974”. If the current year is 2023, and the user input the integer number “19”, the program would output to the console “2019”. The user is not asked to enter the current year; the program captures that automatically. The user only enter the last two numbers of a year. Hopefully, that's enough to go by and clear enough. I need the code,…arrow_forward
- I need help creating a java code program that shows like this Your program should behave as follows. Please enter a number to find the integer log of1234Please enter the base for the calculation2The base 2 integer log of 1234 is 10Would you like to enter another pair of numbers?Please enter "y" for yes or "n" for no.bPlease enter "y" for yes or "n" for no.yPlease enter a number to find the integer log of1234Please enter the base for the calculation5The base 5 integer log of 1234 is 4Would you like to enter another pair of numbers?Please enter "y" for yes or "n" for no.nGood-bye! Problem is Shown in image below:arrow_forwardWrite a program (use value returning method) that gives simple math quizzes. The program should display two random integers from 1 to 100 that are to be added,The program allows the user to enter the answer. If the answer is correct, display “congratulations”. If the answer is incorrect, the program should show the correct answer. using java programmingarrow_forwardIn Java: Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or 1995! the output is: no Hint: Use a loop and the Character.isDigit() function.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





