Advertisement
guygol10

Untitled

Nov 21st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Ex2 {
  3.     public static void main(String [] args){
  4.         Scanner reader = new Scanner(System.in);
  5.         int counter = 0;
  6.         int currentNum=0;
  7.         int largestNum = 0;
  8.         int secLargestNum = 0;
  9.         while (currentNum!=-999)
  10.         {
  11.             System.out.println("enter a number, to stop this program enter -999");
  12.             currentNum = reader.nextInt();
  13.             if (currentNum > secLargestNum && currentNum > largestNum)
  14.             {
  15.                 largestNum = currentNum;
  16.                 if (largestNum > secLargestNum && currentNum < largestNum)
  17.                 {
  18.                     secLargestNum = currentNum;
  19.                 }
  20.             }
  21.             counter++;
  22.         }
  23.             System.out.println("The first is the large number: " + largestNum);
  24.             System.out.println("The second is the large number: " + secLargestNum);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement