它應該是一個詞猜猜遊戲,給5個機會進入一個輔音,然後猜猜這個單詞還沒有完成,但我必須知道這部分程序是否運行良好。我認爲這是給我找麻煩的變量是輔音,元音字母,數字下面是我的代碼:PS IM很新的Java我有錯誤:找不到符號,但我認爲我的變量都被聲明和初始化
public class julia1 {
public static void main(String[] args) {
System.out.print("enter text to guess: ");
String w = Keyboard.readString();
String asterix = "";
for(int c = 0; c < w.length(); c++){
if(w.charAt(c)==(' ')) asterix = asterix + " ";
else asterix = asterix + "*";
}
System.out.println(asterix);
for (int trys = 0; trys <=5; trys++){
String temp="";
System.out.print("enter a consonant: ");
char c1 = Keyboard.readChar();
for (int i = 0; i < w.length(); i++)
{
boolean character = false, vowel = false, consonant =false, number= false;
if (w.charAt(i) >= 'a' &&w.charAt(i)<='z')
character = true;
if (w.charAt(i) >= 'A' && w.charAt(i)<='Z')
character = true;
if (character == true){
switch (w.charAt(i)){
case 'a': case 'A': case 'o': case 'O':
case 'e': case 'E':
case 'i': case 'I':
case 'u': case 'U': vowel = true; break;
if (c1 >= '0' && c1 <='9')
number=true;
default : consonant = true;
}
}
}
for(int c = 0; c < w.length(); c++){
if((w.charAt(c)==c1) && (consonant == true))
temp = temp + c1;
else if (vowel==true)
{temp = temp + asterix.charAt(c);
System.out.println("this is a vowel not consonant");
}
else
temp = temp + asterix.charAt(c)&& number==true;
System.out.println("this is not a valid letter");}
asterix = temp;
System.out.println(asterix) ;
}
}
}
在這行你得到這個錯誤?在這裏發佈編譯器錯誤。 –
哪一行是錯誤? – RNJ
如果((w.charAt(C)== C1)&&(輔音== TRUE)) ^ 符號:可變輔音 位置:類julia1 E:\ julia1 \ SRC \ julia1.java:47:錯誤:無法找到符號 否則,如果(元音==真) ^ 符號:變量元音 位置:類julia1 E:\ julia1的\ src \ julia1.java:52:錯誤:無法找到符號 \t溫度=溫度+星號.charAt(c)&& number == true; \t^ 符號:變量號碼 位置:class julia1 3錯誤 –