每次提示设置错误重新设置之后,将时分秒全部输入之后,会又一次开始运行让再一次设置是多少分,不知道是什么原因,各位帮忙看看,谢谢啦!这个是我的程序运行截图
import java.util.Scanner;
public class TestTime {
public static class Time{
static int hour,minute,second;
static void setTime() {
System.out.print("现在是多少时?");
Scanner input=new Scanner(System.in);
hour=input.nextInt();
if(hour<0||hour>24) {
System.out.println("设置错误,请您重新设置");
Time.setTime();
}
System.out.print("现在是多少分?");
minute=input.nextInt();
if(minute<0) {
System.out.println("设置错误,请您重新设置");
Time.setTime();
}
System.out.print("现在是多少秒?");
second=input.nextInt();
if(second<0) {
System.out.println("设置错误,请您重新设置");
Time.setTime();
}
if(second>=60){
minute+=second/60;
second=second%60;
}
if(minute>=60){
hour+=minute/60;
minute=minute%60;
}
if(hour==24) {
hour=0;
}else if(hour>24) {
hour=hour%24;
}
}
static void showTime() {
System.out.print("现在的时间是");
System.out.println(hour+":"+minute+":"+second);
}
}
public static void main(String[] args) {
Time.setTime();
Time.showTime();
}
}