Answer to Question #289518 in Java | JSP | JSF for Kev

Question #289518

The Big One

by CodeChum Admin


Remember that time when we've tried identifying the largest digit among the given integer? Well, let's take it to the next level, and figure out the same thing on arrays/lists!




Let's do this one more time!




Instructions:


Create a variable that accepts a positive integer.

Create an empty list. Then, using loops, add random integer values into the list one by one. The number of values to be stored is dependent on the inputted positive integer given in the first instruction.

Print out the largest integer among all the elements on the list, by any means necessary.


1
Expert's answer
2022-01-24T08:33:41-0500
import java.util.*;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);


		System.out.print("Enter array size: ");
		int size = keyBoard.nextInt();
		int numbers[] = new int[size];


		for (int i = 0; i < size; i++) {
			System.out.print("Enter the number: ");
			numbers[i] = keyBoard.nextInt();
		}
		int max = numbers[0];
		for (int i = 1; i < size; i++) {
			if (numbers[i] > max) {
				max = numbers[i];
			}
		}
		System.out.println("The largest integer: " + max);


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog