朝花夕拾 Java练习题time
1.编写程序,把560分钟换算成用小时和分钟表示,然后输出。
package com.shangjiti.aoian;
import java.util.Scanner;
public class No7 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int time=560;
int hours=time/60;
int minute=time%60;
System.out.println("560分钟是:"+hours+"小时"+minute+"分");
}
}
2.编写程序,把5600秒换算成用小时,分钟,秒表示,然后输出。
package com.ceshi.aoian;
import java.util.Scanner;
public class ceshi {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int second=0;
int hours=0;
int minute=0;
System.out.println("请输入一个秒数:");
int time=sc.nextInt();
second=time%60; //second=5600%60=20 ---秒
time-=second; //time=5600-20=5580
if(time>0)
{
time/=60; //time=5580/60=93
minute=time%60; //minute=93%60=33 ---分钟
time-=minute; //time=93-33=60
if(time>0)
{
hours=time/60; //hours=60/60=1 ---小时
}
}
System.out.println(hours+"小时"+minute+"分钟"+second+"秒");
}
}