Skip to content

Instantly share code, notes, and snippets.

@j2deme
Last active May 12, 2021 20:52
Show Gist options
  • Save j2deme/020ed8d9e6062df3f1b5ac4556d82924 to your computer and use it in GitHub Desktop.
Save j2deme/020ed8d9e6062df3f1b5ac4556d82924 to your computer and use it in GitHub Desktop.
La Hora Futura
package com.j2deme;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int horaActual = 0, cantidadHoras = 0, horaFinal = 0;
String sufijo = "am";
Scanner teclado = new Scanner(System.in);
System.out.print("Hora Actual: ");
horaActual = teclado.nextInt();
System.out.print("Cantidad de horas: ");
cantidadHoras = teclado.nextInt();
horaFinal = horaActual + cantidadHoras;
while(horaFinal > 24){
horaFinal = horaFinal - 24;
}
if(horaFinal > 12) {
sufijo = "pm";
horaFinal = horaFinal - 12;
}
System.out.printf("En %d horas el reloj marcará las %d %s",cantidadHoras,
horaFinal, sufijo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment