如何将分钟转换为小时? 75分钟 - 1:15

时间:2013-09-30 02:35:21

标签: java

 import java.util.Scanner;

   public class TimeConversion{ 
   public static void main(String[] args) {
    int min= 0;  
    int hours = min / 60; 
        int minutes = min % 60;
    Scanner keyboard = new Scanner(System.in);
    System.out.print("Enter the time in minutes:");
    minutes = keyboard.nextInt();
    System.out.print("The time is: ");

    System.out.printf("%d:%02d", hours, minutes);


}

}

我如何完成代码?

2 个答案:

答案 0 :(得分:3)

试试这个

    int hours = min / 60; 
    int minutes = min % 60;
    System.out.print("The hours is "+hours+" and minutes is "+minutes);

修改

 import java.util.Scanner;

   public class TimeConversion{ 
   public static void main(String[] args) {
   int minutes = min % 60;
   Scanner keyboard = new Scanner(System.in);
   System.out.print("Enter the time in minutes:");
   minutes = keyboard.nextInt();
   int hours = minutes / 60; 
   int minutes1 = minutes % 60;
   System.out.print("The hours is "+hours+" and minutes is "+minutes1);
    }
   }

答案 1 :(得分:-1)

min = keyboard.nextInt();    

int hours = Integer.parseInt(Math.floor(min/60));
int minutes = min % 60;
System.out.print("The time is " + hours + ":" + minutes);