-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcal.java
More file actions
56 lines (44 loc) · 1.75 KB
/
cal.java
File metadata and controls
56 lines (44 loc) · 1.75 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
float number_1, number_2;
System.out.println("Enter first number");
Scanner scan = new Scanner(System.in);
number_1 = scan.nextFloat();
System.out.println("Enter second number");
number_2 = scan.nextFloat();
System.out.print("You have Entered ");
System.out.print(number_1);
System.out.print(" and ");
System.out.println(number_2);
System.out.println("What operation you want to do:- +,-,*,/");
String prompt = "(Enter 0 for addition, 1 for " +
"subtraction, 2 for multiplication and 3 for division)";
System.out.println(prompt);
int input = scan.nextInt();
switch (input){
case 0:
System.out.println("Adding these numbers");
System.out.print("The result is: ");
System.out.println(number_1 + number_2);
break;
case 1:
System.out.println("Subtracting these numbers");
System.out.print("The result is: ");
System.out.println(number_1 - number_2);
break;
case 2:
System.out.println("Multiplying these numbers");
System.out.print("The result is: ");
System.out.println(number_1 * number_2);
break;
case 3:
System.out.println("Dividing these numbers");
System.out.print("The result is: ");
System.out.println(number_1 / number_2);
break;
default:
System.out.println("Invalid input");
}
}
}