Skip to content
Snippets Groups Projects
Commit a7ebb981 authored by Benjamin Kvello-Hansen's avatar Benjamin Kvello-Hansen
Browse files

Update 2 files

- /oppgave2.java
- /oppgave3.java
parent f4ed12ed
No related branches found
No related tags found
No related merge requests found
import java.util.*;
public class Oppgave2 {
static double tidsomregning(double hr, double min, double sec){
double totSec = hr*60*60 + min*60 + sec;
System.out.println(hr+" timer/time, "+min+" minutter/minutt og "+sec+" sekunder/sekund er totalt "+totSec+" sekunder/sekund");
return totSec;
}
public static void main(String[] args){
System.out.println("Hvor mange timer? ");
Scanner inpHr = new Scanner(System.in);
double hr = inpHr.nextFloat();
System.out.println("Hvor mange minutter? ");
Scanner inpMin = new Scanner(System.in);
double min = inpMin.nextFloat();
System.out.println("Hvor mange sekunder? ");
Scanner inpSec = new Scanner(System.in);
double sec = inpSec.nextFloat();
tidsomregning(hr, min, sec);
//datasett
tidsomregning(30, 1, 1);
tidsomregning(1, 1, 1);
tidsomregning(1, 30, 1);
tidsomregning(48, 21, 1);
tidsomregning(0, 0, 1);
tidsomregning(7, 33, 2);
tidsomregning(1, 400, 200);
tidsomregning(0, 103, 0);
}
}
import java.util.*;
public class Oppgave3 {
static int tidsomregning(int totSec){
int hr = totSec / (60*60);
var tempSec = totSec-(hr*60*60);
int min = tempSec/60;
tempSec = tempSec-(min*60);
int sec = tempSec;
System.out.println(totSec+" Sekunder, er "+hr+" timer, "+min+" minutter og "+sec+" sekunder");
return 1;
}
public static void main(String[] args){
System.out.println("Hvor mange sekunder vil du ha i timer, minutter og sekund? ");
Scanner inpSec = new Scanner(System.in);
final int totSec = inpSec.nextInt();
tidsomregning(totSec);
//datasett
tidsomregning(10);
tidsomregning(300);
tidsomregning(4620);
tidsomregning(3661);
tidsomregning(9384);
tidsomregning(2836);
tidsomregning(1298723);
tidsomregning(1);
tidsomregning(60);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment