-
Lenguaje
Java usando Scanner
-
Descripción
Dada una medida de tiempo expresado en horas, minutos y segundos con valores arbitrarios elaboren un algoritmo que transforme dicha medida en una expresión correcto por ejemplo dada la medida:
3 hrs, 118 min, 19 seg
El programa o el algoritmo deberá obtener como resultado:
5 hrs, 1 min, 15 seg
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
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
import java.util.Scanner;
public class TiempoExpresadoEnHorasMinutosYSegundos {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int hrs1, hrs2, min1, min2, seg1;
int seg2;
System.out.print("Ingresa el valor de hrs1: ");
hrs1 = in.nextInt();
in.nextLine();
System.out.print("Ingresa el valor de min1: ");
min1 = in.nextInt();
in.nextLine();
System.out.print("Ingresa el valor de seg1: ");
seg1 = in.nextInt();
in.nextLine();
seg2=seg1%60;
min2=min1+(seg1-seg2)/60;
hrs2=hrs1+(min2-min2%60)/60;
min2=min2%60;
hrs2=hrs2%24;
System.out.println("Valor de hrs2: " + hrs2);
System.out.println("Valor de min2: " + min2);
System.out.println("Valor de seg2: " + seg2);
}
}
public class TiempoExpresadoEnHorasMinutosYSegundos {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int hrs1, hrs2, min1, min2, seg1;
int seg2;
System.out.print("Ingresa el valor de hrs1: ");
hrs1 = in.nextInt();
in.nextLine();
System.out.print("Ingresa el valor de min1: ");
min1 = in.nextInt();
in.nextLine();
System.out.print("Ingresa el valor de seg1: ");
seg1 = in.nextInt();
in.nextLine();
seg2=seg1%60;
min2=min1+(seg1-seg2)/60;
hrs2=hrs1+(min2-min2%60)/60;
min2=min2%60;
hrs2=hrs2%24;
System.out.println("Valor de hrs2: " + hrs2);
System.out.println("Valor de min2: " + min2);
System.out.println("Valor de seg2: " + seg2);
}
}