Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Ex2 {
- public static void main(String [] args){
- Scanner reader = new Scanner(System.in);
- int counter = 0;
- int currentNum=0;
- int largestNum = 0;
- int secLargestNum = 0;
- while (currentNum!=-999)
- {
- System.out.println("enter a number, to stop this program enter -999");
- currentNum = reader.nextInt();
- if (currentNum > secLargestNum && currentNum > largestNum)
- {
- largestNum = currentNum;
- if (largestNum > secLargestNum && currentNum < largestNum)
- {
- secLargestNum = currentNum;
- }
- }
- counter++;
- }
- System.out.println("The first is the large number: " + largestNum);
- System.out.println("The second is the large number: " + secLargestNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement