Question: //-----------------------------------squarerootwhile.java-----------------------------------------------------------> package com.example; import java.util.Scanner; public class SquareRootWhile { public static void main(String args[]) { System.out.print(Type a non-negative integer: ); Scanner console = new Scanner(System.in);

//-----------------------------------squarerootwhile.java----------------------------------------------------------->
package com.example;
import java.util.Scanner;
public class SquareRootWhile {
public static void main(String args[])
{
System.out.print("Type a non-negative integer: ");
Scanner console = new Scanner(System.in);
int number = console.nextInt();
}
}
Import and open the WhileLoopEx project. Modify SquareRootWhile.java to use a while loop to repeatedly prompt users to type a number until they type a non-negative number, and then computes the square root. Expected output: Type a non-negative integer: 5 Invalid number, try again: -1 Invalid number, try again: 11 The square root of 11 is 3.166
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
