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

//-----------------------------------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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!