写一个程序,输出类似09:03:12的时间格式,需要判断输入的数字是否符合实际情况,比如小时数就不能大于24,如果大于24就提示输入错误;分钟数和秒数不能大于60,如果大于60就提示输入错误。
public class demo10 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入三个数");
int t1= sc.nextInt();
int t2= sc.nextInt();
int t3= sc.nextInt();
if(t1>24) {
System.out.println("时钟错误");
} if(t2>60){
System.out.println("分钟错误");
}
if(t3>60){
System.out.println("秒钟错误");
}
System.out.println(t1+":"+t2+":"+t3);
}
}