-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleCalculator.java
More file actions
58 lines (42 loc) · 1.12 KB
/
Copy pathSampleCalculator.java
File metadata and controls
58 lines (42 loc) · 1.12 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
54
55
56
57
58
package day3;
import java.util.Scanner;
public class SampleCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the first number");
double num1 = scanner.nextDouble();
System.out.println("Enter the second number");
double num2 = scanner.nextDouble();
System.out.println("Choose an operation");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
int choice = scanner.nextInt();
if (choice==1) {
System.out.println("Result: "+ (num1+num2));
}
else if (choice==2)
{
System.out.println("Result: "+ (num1-num2));
}
else if (choice==3)
{
System.out.println("Result: "+ (num1*num2));
}
else if (choice==4)
{
if (num2!=0)
{
System.out.println("Result: "+ (num1/num2));
}
else
{
System.out.println("Error: Division by zero is not allowed");
}
} else {
System.out.println("Invalid choice");
}
scanner.close();
}
}