Question: [JAVA] The program below takes a given number of integers entered from the console, allows the user to enter them, and finds the largest entered
[JAVA]
The program below takes a given number of integers entered from the console, allows the user to enter them, and finds the largest entered value.
Rewrite this program to use a method. Your main program should declare, construct, and close the Scanner. It should also call a method that does the work that is done between lines 15 and 29 in the code below. In the end, your main program should be about five lines long. The prompt inside the while loop should be a parameter (there are other parameters).
![[JAVA] The program below takes a given number of integers entered from](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f530df411ff_86266f530dea954b.jpg)
import java.util.Scanner; public class Largest { // Find the largest value of a given number of values entered at the keyboard public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the number of values to be entered"); int numberValues = keyboard.nextInt(); keyboard.nextLine(); // Enter the values and find the largest // Line 15 int count = 0; int max = Integer.MIN_VALUE; // by starting with the smallest value, // we know everything else is larger--this is a constant in the API while (count max) { max = value; } count = count + 1; } // Line 29 System.out.println("The maximum is + max); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
