Here, I have given principle is 1 and still doesn't break out of loop. please clear this

package com.company;

import java.util.Scanner;

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

    while (true) {
        System.out.println("principal(1k - 1M):");
       int principle=scan.nextInt();
        if ((principle< 1000 && principle > 1000000))  {
            break;
        }
        System.out.println("enter a number betweeen 1000 and 1000000");
    }
    
}

}

You only break if a principle is entered that is less than 1000 and greater than 1000000. No integer can satisfy both criteria.

2 Likes

You should enter a value that’s between 1,000 and 1,000 000.
Like this: if ((principle >=1000 && principle <= 1000000)) {
break;
}
So, the value has to be bigger or equal to 1,000 and less or equal to 1,000,000.

1 Like