package com.itheima;
/**
*第3题: 从键盘接受一个数字,打印该数字表示的时间,最大单位到天,例如:
键盘输入6,打印6秒;
键盘输入60,打印1分;
键盘输入66,打印1分6秒;
键盘输入666,打印11分6秒;
键盘输入3601,打印1小时1秒
*@author Han
*/
import java.util.*;
import java.lang.*;
import javax.print.attribute.standard.Finishings;
public class Test3 {
public static void main(String[] args)
{
int second,minute,hour,day;
Scanner sc=new Scanner(System.in);
int time=1;
System.out.println("请输入一个整数:");
while(time!=0) {
try{
time=sc.nextInt();
}
catch(Exception e){
System.out.print("请输入整数!!!");
break;
}
finally{
}
if(time>=216000)
{
day=time/216000;
time=time%216000;
System.out.print(day+"天");
}
if(time>=3600)
{
hour=time/3600;
time=time%3600;
System.out.print(hour+"小时");
}
if(time>=60)
{
minute=time/60;
time=time%60;
System.out.print(minute+"分钟");
}
if(time>0)
{
second=time;
System.out.print(second+"秒");
}
System.out.println();
}
}
}
已经进行了异常处理,但是还感觉不太好,怎么才能在输出异常后再提示输出?循环起来
|
|