// CSE 142, Summer 2008 (Helene Martin) // Prompts the user for a non-negative integer and prints its square root. // If negative numbers are given, re-prompt. import java.util.*; public class SquareRoot { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Type a non-negative integer: "); int num = console.nextInt(); while(num < 0) { System.out.print("Invalid number, try again: "); num = console.nextInt(); } System.out.println("The square root of " + num + " is " + Math.sqrt(num)); } }