Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ø
Øving 2
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Programmering 1 Øvinger
Øving 2
Commits
49ad35e1
Commit
49ad35e1
authored
7 months ago
by
Benjamin Kvello-Hansen
Browse files
Options
Downloads
Patches
Plain Diff
Update 2 files
- /oppgave1.java - /oppgave2.java
parent
7acbaa43
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
oppgave1.java
+41
-0
41 additions, 0 deletions
oppgave1.java
oppgave2.java
+25
-0
25 additions, 0 deletions
oppgave2.java
with
66 additions
and
0 deletions
oppgave1.java
+
41
−
0
View file @
49ad35e1
import
java.util.*
;
public
class
Oppgave1
{
static
int
skuddar
(
int
ar
){
if
(
ar
%
100
==
0
){
if
(
ar
%
400
==
0
){
System
.
out
.
println
(
ar
+
" er et skuddår"
);
return
2
;
}
else
{
System
.
out
.
println
(
ar
+
" er ikke et skuddår"
);
return
1
;
}
}
else
if
(
ar
%
4
==
0
)
{
System
.
out
.
println
(
ar
+
" er et skuddår"
);
return
2
;
}
System
.
out
.
println
(
ar
+
" er ikke et skuddår"
);
return
1
;
}
public
static
void
main
(
String
[]
args
){
System
.
out
.
println
(
"Hvilket år vil du finne ut om er skuddår? "
);
Scanner
inpAr
=
new
Scanner
(
System
.
in
);
int
ar
=
inpAr
.
nextInt
();
skuddar
(
ar
);
//datasett
skuddar
(
400
);
skuddar
(
2024
);
skuddar
(
12
);
skuddar
(
3049
);
skuddar
(
2025
);
skuddar
(
2026
);
skuddar
(
2027
);
skuddar
(
2028
);
}
}
This diff is collapsed.
Click to expand it.
oppgave2.java
0 → 100644
+
25
−
0
View file @
49ad35e1
public
class
Oppgave2
{
public
static
void
main
(
String
[]
args
)
{
double
prisA
=
35.90
;
double
gramA
=
450
;
double
prisB
=
39.50
;
double
gramB
=
500
;
double
prisPerGramA
=
prisA
/
gramA
;
double
prisPerGramB
=
prisB
/
gramB
;
// Utskrift av resultatet
System
.
out
.
println
(
"Pris per gram for merke A: "
+
prisPerGramA
+
" kr"
);
System
.
out
.
println
(
"Pris per gram for merke B: "
+
prisPerGramB
+
" kr"
);
if
(
prisPerGramA
<
prisPerGramB
)
{
System
.
out
.
println
(
"Merke A er billigst."
);
}
else
if
(
prisPerGramA
>
prisPerGramB
)
{
System
.
out
.
println
(
"Merke B er billigst."
);
}
else
{
System
.
out
.
println
(
"Begge merkene har samme pris per gram."
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment