JAVA - While infinity bucle =/

import java.util.Scanner;

public class Ejercicio1 {

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

    System.out.println("Enter a number: ");
    n = reader.nextInt();
    while (n >= 0){
       square = (int)Math.pow(n, 2);
        System.out.println("The number to square is:  "+square);
    }
}

}

NOTE: prints endless times n, anybody can help me?

Well what currently makes the condition fail?

You need to create an exit condition.

3 Likes

Thank You, after of read how works while, I could fixed issue.

Solution:

import java.util.Scanner;

public class Ejercicio1 {

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

    System.out.println("Enter a number positive: ");
    n = reader.nextInt();
    while (n >= 0){
        square = (int)Math.pow(n, 2);
        System.out.println("The number to square is:  "+square);
        n = reader.nextInt();
    }
    System.out.println("The number is negative");

}