很抱歉的基本問題 - 剛開始對JAVA讓用戶重新輸入值,如果值不正確
試圖驗證價值的用戶,進入前下一個值將輸入序列 - 程序運行到下一個if語句按順序,而不是要我重新輸入開始時間...
System.out.println("Enter start time in 24 hr format eg 0800 ");
startTime = in.nextInt();
if (startTime >=0000 && startTime <=2400) // verify hours
{
System.out.println ("thank you start hours entered ");
}
else
if (startTime >2400) // verify hours
{
System.out.println ("invalid start hours ! please re-enter ");
}
System.out.println("Enter stop time in 24 hr format eg 1700 ");
stopTime = in.nextInt();
if (stopTime >=0000 && stopTime <=2400) // verify hours
{
System.out.println ("thank you stop hours entered ");
}
else
if (stopTime >2400)
{
System.out.println ("invalid stop hours ! please re-enter ");
}
// proceed with rest of program
請注意,你的程序將接受像小時其中0099是不是有效的時間! – Sanchises 2014-10-19 09:25:39