Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions GreatestOfFourUsingList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.Scanner;
import java.util.*;
import java.util.Optional;
import java.util.Comparator;

public class GreatestOfFourUsingList {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> list = new ArrayList<>();
System.out.println("Please enter first number: ");
list.add(sc.nextInt());
System.out.println("Please enter second number: ");
list.add(sc.nextInt());
System.out.println("Please enter third number: ");
list.add(sc.nextInt());
System.out.println("Please enter fourth number: ");
list.add(sc.nextInt());

System.out.println("Largest of four numbers is: " + list.stream().max(Integer::compare).get());
sc.close();
}
}