日食时间转换,遇到麻烦

时间:2016-05-11 02:58:37

标签: java eclipse

package timeConversion;
import java.util.Scanner;

public class TimeConversion {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter the time in minutes: ");
        int time = input.nextInt();//time in minutes
        int hour = time / 60;// hour 
        int minute = time % 60; //minutes
        System.out.print("The time is: " + hour + ":" + minute);


    }

}

所以我在分钟点的值小于10时遇到问题。例如,当你在184分钟的时间内,输出是3:4,但我希望它读到3:04。我怎么能这样做呢?

1 个答案:

答案 0 :(得分:0)

快速破解

if(minute < 10)
    System.out.println("The time is: " + hour + ":0" + minute);
else
    System.out.print("The time is: " + hour + ":" + minute);