// Repeatedly prompts the user for numbers until // a non-negative number is entered. import java.util.*; public class Negatives { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Type a non-negative integer: "); int n = console.nextInt(); while (n < 0) { System.out.print("Invalid number, try again: "); n = console.nextInt(); } System.out.println(n + " squared is " + n*n); } }