额。。。我比较笨,笨办法,不会贴代码-_-
import java.io.IOException;
import java.util.Scanner;
class TimeTest
{
public static void main(String[] args) throws IOException
{
method();
}
public static void method() throws IOException
{
Scanner sc = new Scanner(System.in); //请问这句什么意思呀 百度的。用毕老师的键盘输入没捣鼓出来- -
System.out.println("请输入一个数字:");
int n = sc.nextInt();
TimeZhuanHuan(n);
}
private static long TimeZhuanHuan(long t)
{
if (t<0)
throw new RuntimeException("你是来捣乱的吗?");
else if(t<60)
System.out.println(t+"秒");
else if(t<3600)
{
if(t%60==0)
System.out.println(t/60+"分");
else
System.out .println(t/60+"分"+(t%60)+"秒");
}
else if(t<86400)
{
if(t%3600==0)
System.out.println(t/3600+"小时");
else if(t%60==0)
System.out.println(t/3600+"小时"+(t%3600)/60+"分");
else if((t%3600)<60)
System.out.println(t/3600+"小时"+(t%3600)+"秒");
else
System.out.println(t/3600+"小时"+(t%3600)/60+"分"+t%60+"秒");
}
else if(86400<=t)
{
if(t%86400==0)
System.out.println(t/86400+"天");
else if(t%3600==0)
System.out.println(t/86400+"天"+(t%86400)/3600+"小时");
else if(t%60==0)
System.out.println(t/86400+"天"+(t%86400)/3600+"小时"+(t%3600)/60+"分");
else if(t%86400<60)
System.out.println(t/86400+"天"+t%86400+"秒");
else if(t%86400<3600)
System.out.println(t/86400+"天"+(t%3600)/60+"分"+t%60+"秒");
else
System.out.println(t/86400+"天"+(t%86400)/3600+"小时"+(t%3600)/60+"分"+t%60+"秒");
}
return t;
}
}
|