我遇到了一個問題,我的方法之一。我一遍又一遍地檢查過,我似乎無法找到任何錯誤。我遇到的問題是該方法在調用它時不在控制檯中打印。我認爲這可能與該方法中的掃描儀有關。方法不打印/返回
該方法的代碼是:
public String cpuGuess() throws FileNotFoundException{
Scanner fileRead = new Scanner(myGuesses);
int line = rand.nextInt(99-1)+1;
for(int i = 0; i <= line; i++){
Guess = fileRead.next();
}
fileRead.close();
CPUGuess = Guess;
if(Arrays.asList(super.used).contains(CPUGuess)){
System.out.println(cpu.cpuGuess());
}
else{
StringBuffer hiddenBuff = new StringBuffer(hidden);
for (int t = 0; t < phrase.length();)
if (CPUGuess == Character.valueOf(phrase.charAt(t)).toString()){
count++;
}
if (phrase.contains(CPUGuess)){
ArrayList<Integer> indicies = new ArrayList<Integer>();
for (int index = phrase.indexOf(CPUGuess.toString()); index >= 0; index = phrase.indexOf(CPUGuess.toString(), index + 1)){
indicies.add(index);
}
int[] index = new int[indicies.size()];
for(int i = 0; i < indicies.size(); i++) {
index[i] = indicies.get(i);
}
for (int n = 0; n < index.length; n++){
hiddenBuff.setCharAt(index[n], CPUGuess.charAt(0));
}
hidden = hiddenBuff.toString();
status = "Correct";
}
else if (!phrase.contains(CPUGuess)){
System.out.println("Sorry, no " + Guess + "'s");
System.out.println("Human, you're up!");
}
super.used.add(CPUGuess.charAt(0));
}
System.out.println(count + " " + CPUGuess + "s");
count = 0;
return hidden;
}
我叫主類中的方法主要方法下:
public static void main(String[] args) throws FileNotFoundException {
System.out.println("WHEEL... OF... FORTUNE!!!!");
System.out.println(board.phraseGenerate());
System.out.println(cpu.cpuGuess());
}
請注意CPU的對象已經被構造和董事會.phraseGenerate創建隱藏和短語。
感謝您的幫助,請不要居高臨下,我在這方面比較新,而且我看到很多帖子都令人灰心。
你得到**「輪...與財富!!!!」 **在當您運行控制檯日誌碼? – Raf
是的,這裏是控制檯的一個例子 –
WHEEL ... OF ... FORTUNE !!!! S T A R W A R S _ _ _ _ _ _ _ _ –