-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
49 lines (38 loc) · 1.18 KB
/
Main.java
File metadata and controls
49 lines (38 loc) · 1.18 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
// Java program for simple calculator
import java.lang.*;
import java.util.Scanner;
// Driver class
class Main {
// main function
public static void main(String[] args)
{
// Stores two numbers
double number1;
double number2;
// Take input from the user
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the numbers:");
// Take the inputs
number1 = scanner.nextDouble();
System.out.println("Enter the operator (+,-,*,/):");
char operator = scanner.next().charAt(0);
double result = 0;
switch (operator) {
// case to add two numbers
case '+':
result = number1 + number2;
break;
// case to divide two numbers
case '/':
result = number1 / number2;
break;
default:
System.out.println("Unknown operator");
}
System.out.println("The final result:");
System.out.println();
// print the final result
System.out.println(number1 + " " + operator + " " + number2
+ " = " + result);
}
}