mardi 7 janvier 2020

"If" Statement Will Not Print in Loop

My code works, there's is just one problem. The code is meant to be about printing the numbers in between two user inputs. That part of the code works, however if the first number is greater than the second number it is meant to not print and ask again. Everything up to that point works, however if the first number is greater than the second, the console and code just end, and I cannot figure out why? Can you guys help and explain what I am doing wrong? Thanks! Here is my code:

public static void main(String[] args) {
    Scanner reader = new Scanner(System.in);

    int higherNum, lowerNum;

    System.out.print("First: ");
    lowerNum=Integer.parseInt(reader.nextLine());

    System.out.print("Second: ");
    higherNum=Integer.parseInt(reader.nextLine());

    while (higherNum>=lowerNum){
        if (lowerNum>higherNum){
            System.out.print("Sorry, you put your first number higher than your second, please make your first number a smaller number than your second. "); // this does not print 
        }
    }

    System.out.println(lowerNum++);
}

Aucun commentaire:

Enregistrer un commentaire