我是新來的java,我試圖要求用戶輸入,但我不希望用戶能夠輸入兩次相同的數字。以下是我試圖用戶輸入,不允許相同的輸入兩次
g1 = iBox.getInteger("Enter your 1st number");
g2 = iBox.getInteger("Enter your 2nd number");
if(g1 == g2){
g2 =iBox.getInteger("Number used, please re-enter");
}
g3 = iBox.getInteger("Enter your 3rd number");
if(g3 == g1){
g3 =iBox.getInteger("Number used, please re-enter");
}
else if(g3 == g2){
g3 =iBox.getInteger("Number used, please re-enter");
}
g4 = iBox.getInteger("Enter your 4th number");
if(g4 == g1){
g4 =iBox.getInteger("Number used, please re-enter");
}
else if(g4 == g2){
g4 =iBox.getInteger("Number used, please re-enter");
}
else if(g4 == g3){
g4 =iBox.getInteger("Number used, please re-enter");
}
oBox.print(" " + g1 + " " + g2 + " " + g3 + " " + g4 + " ");
你有什麼問題嗎? – chance
這裏沒有問題。 「iBox」是什麼類型? –
我們可以獲得更多信息嗎?拋出什麼異常(如果有的話)?想必你正在經歷意想不到的行爲。你能詳細說明這種行爲嗎?我很樂意提供幫助;我只需要知道什麼不適用於您的代碼(因爲乍一看,它看起來不錯) –