-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqrtCalc.java
More file actions
32 lines (28 loc) · 911 Bytes
/
SqrtCalc.java
File metadata and controls
32 lines (28 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
public class SqrtCalc {
public static void main(String[] args) {
String chars;
double x;
Scanner obj = new Scanner(System.in);
do {
do {
System.out.println("Enter a number: ");
x = obj.nextDouble();
if(x<0)
System.out.println(">>>number must be positive<<<");
}
while(x<0);
chars = obj.nextLine();
System.out.println("Square root of " + x + " is " + Math.sqrt(x));
do {
System.out.print("Do you wish to continue? (yes or no) :");
chars = obj.nextLine();
if (!chars.contentEquals("yes") && !chars.contentEquals("no"))
System.out.println(">>>Please respond with (yes or no)<<<");
}
while((!chars.contentEquals("yes")) && (!chars.contentEquals("no")));
}
while(chars.equals("yes"));
System.out.println("bye");
}
}