Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Test3 {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- int max1 = Integer.MIN_VALUE + 3;
- int max2 = Integer.MIN_VALUE + 2;
- int max3 = Integer.MIN_VALUE + 1;
- int stopNum = Integer.parseInt(reader.nextLine());
- int input;
- for (int i = 1; i <= stopNum ; i++) {
- input = Integer.parseInt(reader.nextLine());
- if (input > max1) {
- max3 = max2;
- max2 = max1;
- max1 = input;
- }
- if (input < max1 && input > max3) {
- if(input > max2) {
- max3 = max2;
- max2 = input;
- }
- }
- if (input < max1 && input < max2) {
- if (input > max3) {
- max3 = input;
- }
- }
- }
- System.out.println(max1 + ", " + max2 + " and " + max3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment