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:
Input
The first line contains the size of the array/list.
The next lines contains an integer on each.
5
5
34
3
23
10
Output
A line containing an integer.
34
package com.task;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Input number: ");
Scanner in = new Scanner(System.in);
Integer itemNumber = Integer.valueOf(in.nextLine());
List<Integer> list = new ArrayList<Integer>();
Integer nextInt;
for (int i = 0; i < itemNumber; i++) {
nextInt = new Random().nextInt(100);
list.add(nextInt);
System.out.println("Generated integer: " + nextInt);
}
Integer maxInt = 0;
for (Integer listInt : list) {
if (listInt > maxInt) {
maxInt = listInt;
}
}
System.out.println("Max integer: " + maxInt);
}
}
Comments
Leave a comment