Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (41 loc) · 1.34 KB
/
Copy pathMain.java
File metadata and controls
45 lines (41 loc) · 1.34 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
import java.util.Scanner;
/**
* Main
*/
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter First Number: ");
double num1=sc.nextDouble();
System.out.println("Enter Second Number: ");
double num2=sc.nextDouble();
System.out.println("Choose Operation:");
System.out.println("1.Addition (+)");
System.out.println("2.Subtraction (-)");
System.out.println("3.Multiplication (*)");
System.out.println("4.Division (+)");
System.out.print("Enter your choice (1-4): ");
int choice=sc.nextInt();
switch (choice) {
case 1:
System.out.println("Result = "+(num1+num2));
break;
case 2:
System.out.println("Result = "+(num1-num2));
break;
case 3:
System.out.println("Result = "+(num1*num2));
break;
case 4:
if(num2!=0){
System.out.println("Result = " + (num1 / num2));
}else{
System.out.println("Cannot divide by zero.");
}
break;
default:
System.out.println("Invalid Choice!");;
}
sc.close();
}
}