문제
초를 입력 받아, 시, 분, 초를 계산하는 문제입니다 실행순서를 클릭하세요
초를 입력하세요: 3661
3661초는 1시간 1분 1초입니다.
프로그램 코드
import java.util.Scanner;
public class Time
{
1 public static void main( String[] args ) {
Scanner scan = new Scanner( System.in );
System.out.print( "초를 입력하세요: " );
2 int totalSeconds = scan.nextInt();
3 int hours = totalSeconds / ( 60 * 60 );
4 int minutes = ( totalSeconds % ( 60 * 60 ) ) / 60;
5 int seconds = totalSeconds % 60;
6 System.out.print( totalSeconds + "초는 " + hours + "시간 " + minutes + "분 " + seconds + "초입니다." );
scan.close();
7 }
}