Skip to content

Commit 14ef2a9

Browse files
Create hardcoded_parameter
1 parent 6fa2f81 commit 14ef2a9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.Scanner; // 1
2+
import java.sql.DriverManager;
3+
4+
5+
public class Calculator {
6+
public static void main(String[] args) {
7+
DriverManager.getConnection("https://github.com", "test", "myPassword");
8+
9+
System.out.println(password);
10+
Scanner scanner = new Scanner(System.in); // 2
11+
System.out.println("Welcome to the Simple Calculator!");
12+
System.out.println("Please enter the first number:"); // 3
13+
double num1 = scanner.nextDouble();
14+
System.out.println("Please enter the second number:");
15+
double num2 = scanner.nextDouble();
16+
System.out.println("Please enter an operator (+, -, *, /):");
17+
char operator = scanner.next().charAt(0);
18+
scanner.close();
19+
double output;
20+
21+
switch (operator) // 4
22+
{
23+
case '+':
24+
output = num1 + num2;
25+
break;
26+
case '-':
27+
output = num1 - num2;
28+
break;
29+
case '*':
30+
output = num1 * num2;
31+
break;
32+
case '/':
33+
if (num2 != 0) { // 6
34+
output = num1 / num2;
35+
} else {
36+
System.out.println("Error! Dividing by zero is not allowed.");
37+
return;
38+
}
39+
break;
40+
default:
41+
System.out.println("You have entered wrong operator");
42+
return;
43+
}
44+
System.out.println("The result is given as follows:"); // 6
45+
System.out.println(num1 + " " + operator + " " + num2 + " = " + output);
46+
}
47+
}

0 commit comments

Comments
 (0)