Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pcz_xyz
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
pcz_xyz
Commits
35ec2d32
Commit
35ec2d32
authored
Oct 25, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kalk 1-metodowy 1
parent
5ab198b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
ProgramJednometodowy.java
src/main/java/kalkulatory/ProgramJednometodowy.java
+31
-0
No files found.
src/main/java/kalkulatory/ProgramJednometodowy.java
0 → 100644
View file @
35ec2d32
package
kalkulatory
;
import
java.util.Scanner
;
public
class
ProgramJednometodowy
{
public
static
void
main
(
String
[]
args
)
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
while
(
true
)
{
System
.
out
.
println
(
"Podaj działanie jako + 2 3 lub Q, aby zakończyć"
);
String
operacja
=
sc
.
next
();
if
(
"Q"
.
equalsIgnoreCase
(
operacja
))
{
break
;
}
int
liczba1
=
sc
.
nextInt
();
int
liczba2
=
sc
.
nextInt
();
int
wynik
=
oblicz
(
liczba1
,
liczba2
,
operacja
);
System
.
out
.
printf
(
"%d %s %d = %d\n"
,
liczba1
,
operacja
,
liczba2
,
wynik
);
}
System
.
out
.
println
(
"nara"
);
}
public
static
int
oblicz
(
int
liczba1
,
int
liczba2
,
String
operacja
)
{
switch
(
operacja
)
{
case
"+"
:
return
liczba1
+
liczba2
;
case
"-"
:
return
liczba1
-
liczba2
;
case
"*"
:
return
liczba1
*
liczba2
;
case
"/"
:
return
liczba1
/
liczba2
;
default
:
throw
new
IllegalArgumentException
(
"Nieznane "
+
operacja
);
}
}
}
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