FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/Basic-Java/AlgrebraicOperationsSwitchCase.java at master · iamarav/Java-Programs · GitHub
iamarav
/
Java-Programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
Basic-Java
/
AlgrebraicOperationsSwitchCase.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (48 loc) · 1.36 KB
Breadcrumbs
Java-Programs
/
Basic-Java
/
AlgrebraicOperationsSwitchCase.java
Copy path
File metadata and controls
59 lines (48 loc) · 1.36 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.
Scanner
;
public
class
AlgrebraicOperationsSwitchCase
{
public
static
void
main
(
String
args
[]) {
//Declaring variables
double
n1
,
n2
,
res
=
0
;
System
.
out
.
println
(
"Algebraic Operations of two Numbers with Switch Case Loop
\n
---"
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Enter the number 1: "
);
n1
=
scanner
.
nextDouble
();
System
.
out
.
println
(
"Enter the number 2: "
);
n2
=
scanner
.
nextDouble
();
System
.
out
.
println
(
"---
\n
Enter 1 for addition or
\n
2 for subtraction or
\n
3 for multiplication or
\n
4 for division"
);
int
operator
=
scanner
.
nextInt
();
//Solving by switch case loop for simpler code.
switch
(
operator
) {
case
1
:
res
=
n1
+
n2
;
break
;
case
2
:
res
=
n1
-
n2
;
break
;
case
3
:
res
=
n1
*
n2
;
break
;
case
4
:
res
=
n1
/
n2
;
break
;
default
:
System
.
out
.
println
(
"You have chosen a wrong option.
\n
Please choose from the above given options."
);
end
();
}
System
.
out
.
println
(
res
);
end
();
scanner
.
close
();
}
static
void
end
() {
System
.
out
.
println
(
"---
\n
Enter Y to continue or any key to exit!"
);
Scanner
getEndOption
=
new
Scanner
(
System
.
in
);
String
option
=
getEndOption
.
next
();
if
(
option
.
equalsIgnoreCase
(
"Y"
)) {
main
(
null
);
}
else
{
System
.
out
.
println
(
"The Program has ended. Please run the program again."
);
}
getEndOption
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL