Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_java2b_20250412
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alx_java2b_20250412
Commits
3fa7f49a
Commit
3fa7f49a
authored
Apr 26, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kalkulator - switch
parent
1ad89f46
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
Kalkulator.java
PC22-Serwlety/src/main/java/serwlety/Kalkulator.java
+11
-3
No files found.
PC22-Serwlety/src/main/java/serwlety/Kalkulator.java
View file @
3fa7f49a
...
...
@@ -32,17 +32,25 @@ public class Kalkulator extends HttpServlet {
<form>
Podaj pierwszą liczbę: <input type='text' name='liczba1'><br>
Podaj drugą liczbę: <input type='text' name='liczba2'><br>
Podaj znak działania: <input type='text' name='operacja'><br>
<button>Oblicz</button>
</form>
"""
);
String
operacja
=
request
.
getParameter
(
"operacja"
);
String
liczba1
=
request
.
getParameter
(
"liczba1"
);
String
liczba2
=
request
.
getParameter
(
"liczba2"
);
if
(
liczba1
!=
null
&&
liczba2
!=
null
)
{
if
(
operacja
!=
null
&&
liczba1
!=
null
&&
liczba2
!=
null
)
{
long
x
=
Long
.
parseLong
(
liczba1
);
long
y
=
Long
.
parseLong
(
liczba2
);
long
wynik
=
x
+
y
;
long
wynik
=
switch
(
operacja
)
{
case
"+"
->
x
+
y
;
case
"-"
->
x
-
y
;
case
"*"
->
x
*
y
;
case
"/"
->
x
/
y
;
case
"%"
->
x
%
y
;
default
->
0
;
};
out
.
append
(
"<div>Wynik: "
+
wynik
+
"</div>"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment