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

25 lines
771 B
Java
Raw Normal View History

2023-02-18 14:09:11 +00:00
package aula02;
// Código da package utils disponível em
// https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/utils
2023-02-18 14:09:11 +00:00
import utils.UserInput;
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: ");
2023-02-18 14:09:11 +00:00
int totalSecs = (int) UserInput.getPositiveNumber(sin);
2023-02-17 23:33:57 +00:00
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);
2023-02-20 10:14:11 +00:00
sin.close();
2023-02-17 23:33:57 +00:00
}
}