package org.interview.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class LargestNumber {
public static void main (String [] args ) throws Exception {
List<Integer> il = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
int i;
do{
i = sc.nextInt();
il.add(i);
} while (i != -1);
System.out.println("List:"+il);
for (int in : il) {
if (in > i)
i = in;
}
System.out.println("Largest Number:"+ i);
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class LargestNumber {
public static void main (String [] args ) throws Exception {
List<Integer> il = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
int i;
do{
i = sc.nextInt();
il.add(i);
} while (i != -1);
System.out.println("List:"+il);
for (int in : il) {
if (in > i)
i = in;
}
System.out.println("Largest Number:"+ i);
}
}
No comments:
Post a Comment