-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
60 lines (53 loc) · 1.89 KB
/
Copy pathMain.java
File metadata and controls
60 lines (53 loc) · 1.89 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
59
60
/*
1.
Accept i/ps from User , till user enters "5" or any other option.
I/P : operation(add|sub|mult|div : 1 | 2|3|4) , number1(double) , number2(double)
Display the result of the operation.
*/
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
//System.out.println("Hello World");
Scanner sc = new Scanner(System.in);
boolean exit = false;
while(!exit){
System.out.println("Choose options:\n1.Addition\n2.Substraction\n3.Multiplication\n4.Division\n5.Exit");
int n = sc.nextInt();
double num1, num2;
switch(n){
case 1:
System.out.println("Enter two numbers: ");
num1 = sc.nextDouble();
num2 = sc.nextDouble();
System.out.printf("Addition of %.2f and %.2f: %.2f",num1,num2,(num1+num2));
System.out.println();
break;
case 2:
System.out.println("Enter two numbers: ");
num1 = sc.nextDouble();
num2 = sc.nextDouble();
System.out.printf("Substraction of %.2f and %.2f: %.2f",num1,num2,(num1-num2));
System.out.println();
break;
case 3:
System.out.println("Enter two numbers: ");
num1 = sc.nextDouble();
num2 = sc.nextDouble();
System.out.printf("Multiplication of %.2f and %.2f: %.2f",num1,num2,(num1*num2));
System.out.println();
break;
case 4:
System.out.println("Enter two numbers: ");
num1 = sc.nextDouble();
num2 = sc.nextDouble();
System.out.printf("Division of %.2f and %.2f: %.2f",num1,num2,(num1/num2));
System.out.println();
break;
case 5:
exit = true;
break;
}
}
}
}