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?
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");