-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlgebraicOperations.java
62 lines (47 loc) · 1.23 KB
/
AlgebraicOperations.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Scanner;
public class AlgebraicOperations {
public static void main(String args[]) {
//Declaring variables
double n1,n2,res = 0;
System.out.println("Algebraic Operations of two Numbers\n---");
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number 1: ");
n1 = scanner.nextDouble();
System.out.println("Enter the number 2: ");
n2 = scanner.nextDouble();
System.out.println("---\nEnter 1 for addition,\n2 for subtraction\n3 for multiplication\n4 for division");
int operator = scanner.nextInt();
//Solving by if else loops
if(operator==1) {
res =n1+n2;
}
else if(operator==2) {
res =n1-n2;
}
else if(operator==3) {
res =n1*n2;
}
else if(operator==4) {
res =n1/n2;
}
else{
System.out.println("Error!");
end();
}
System.out.println(res);
end();
scanner.close();
}
static void end() {
System.out.println("Enter Y to continue or any key to exit!");
Scanner getEndOption= new Scanner(System.in);
String option = getEndOption.next();
if(option.equalsIgnoreCase("Y")) {
main(null);
}
else {
System.out.println("The Program has ended. Please run the program again.");
}
getEndOption.close();
}
}