Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
SafeSquareRoot.java
import java.util.Scanner; public class SafeSquareRoot { public static void main( String[] args ) { Scanner keyboard = new Scanner(System.in); int n; System.out.println( "SQUARE ROOT!" ); System.out.print( "Enter a number: " ); n = keyboard.nextInt(); double sr = Math.sqrt(n); while ( n <= 0 ) { System.out.println( "You can't take the square root of a negative number, silly." ); System.out.print( "Try again: " ); n = keyboard.nextInt(); sr = Math.sqrt(n); } System.out.println( "The square root of " + n + " is " + sr + "." ); } }
run
|
edit
|
history
|
help
0
Generics
How to count the occurrence of each character in a string?
Exception handling2
Covariance & Contravariance
Towers of Hanoi
prime number
1
Intuit // C# // listing_4.5 (Math. /Pow /Sin)
GGT
Checking time span between two timezone times