uaveiro-leci/1ano/2semestre/poo/aula02/src/SecsToHMS.java

20 lines
625 B
Java
Raw Normal View History

2023-02-17 23:33:57 +00:00
import java.util.Scanner;
// Solução do exercício 6
public class SecsToHMS {
public static void main(String[] args){
Scanner sin = new Scanner(System.in);
System.out.println("Introduza os segundos totais: ");
int totalSecs;
do {
totalSecs = sin.nextInt();
} while (totalSecs <= 0);
int secs = totalSecs % 60;
int mins = Math.round((float) (totalSecs / 60));
int hours = Math.round((float) (mins / 60));
mins = mins % 60;
System.out.printf("%d segundos no formato hh:mm:ss : %d:%d:%d", totalSecs, hours, mins, secs);
}
}