-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain1.java
More file actions
53 lines (39 loc) · 1.51 KB
/
Main1.java
File metadata and controls
53 lines (39 loc) · 1.51 KB
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
import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Calculator cal = new Calculator();
char choice;
do {
System.out.print("Enter 1st number: ");
int n1 = sc.nextInt();
System.out.print("Enter 2nd number: ");
int n2 = sc.nextInt();
System.out.print("Enter operation (+ - * / %): ");
char op = sc.next().charAt(0);
switch (op) {
case '+':
System.out.println("Result: " + cal.add(n1, n2));
break;
case '-':
System.out.println("Result: " + cal.sub(n1, n2));
break;
case '*':
System.out.println("Result: " + cal.multiply(n1, n2));
break;
case '/':
System.out.println("Result: " + cal.divide(n1, n2));
break;
case '%':
System.out.println("Result: " + cal.modular(n1, n2));
break;
default:
System.out.println("Invalid operation");
}
System.out.print("Do you want to continue (y/n): ");
choice = sc.next().charAt(0);
} while (choice == 'y' || choice == 'Y');
sc.close();
System.out.println("Program ended.");
}
}