0
我有一個任務來編寫一個應用程序,該應用程序將接受來自用戶的輸入,並將每個答案存儲在一個字符串數組中。此應用程序還必須檢查用戶輸入的空值,並重新提示用戶輸入其答案。應用程序必須只重複空白的問題,因爲這個應用程序有50個問題。循環檢查用戶輸入的空白空間
這是到目前爲止我的代碼:
for(iLoop=0; iLoop<noOfQuest; iLoop++)
{
if(noOfEmails<1)
{
System.out.println("FILE_ERROR: Please ensure line \"noOfEmails\" is more than 0");
}
if(noOfQuest==1)
{
System.out.println(prefinalMess);
System.out.println(questionArr[0]);
ansArray[iLoop]=ans.next();
System.out.println(finalMess);
}
if(noOfQuest==2)
{
System.out.println(questionArr[0]);
ansArray[iLoop]=ans.next();
System.out.println(prefinalMess);
System.out.println(questionArr[1]);
ansArray[iLoop]=ans.next();
System.out.println(finalMess);
}
if(noOfQuest==3)
{
System.out.println(questionArr[0]);
ansArray[iLoop]=ans.next();
System.out.println(questionArr[1]);
ansArray[iLoop]=ans.next();
System.out.println(prefinalMess);
System.out.println(questionArr[2]);
ansArray[iLoop]=ans.next();
System.out.println(finalMess);
}
if(noOfQuest==4)
{
System.out.println(questionArr[0]);
ansArray[iLoop]=ans.next();
System.out.println(questionArr[1]);
ansArray[iLoop]=ans.next();
System.out.println(questionArr[2]);
ansArray[iLoop]=ans.next();
System.out.println(prefinalMess);
System.out.println(questionArr[3]);
ansArray[iLoop]=ans.next();
System.out.println(finalMess);
}
if(noOfQuest==5)
{
System.out.println(questionArr[0]);
ansArray[iLoop]=ans.next();
System.out.println(questionArr[1]);
ansArray[iLoop]=ans.next();
System.out.println(questionArr[2]);
ansArray[iLoop]=ans.next();
System.out.println(questionArr[3]);
ansArray[iLoop]=ans.next();
System.out.println(prefinalMess);
System.out.println(questionArr[3]);
ansArray[iLoop]=ans.next();
System.out.println(finalMess);
}
}
我還必須開發新方法來檢查每個答案的輸入。
非常感謝,讓我當涉及到添加更多問題時,工作更容易:3 – 2015-02-10 14:50:02