它应该是一个猜词游戏,在猜词之前有 5 次输入辅音的机会。它仍然不完整,但我必须知道这部分程序是否运行良好。我认为给我带来麻烦的变量是辅音,元音,数字这是我的代码: ps im very new to 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) ;
}
}
}