问题:猜字游戏
import java.util.Scanner;public class T{
public static void main(String[] args){
//create a Scanner
Scanner input = new Scanner(System.in);
String[] word = {"write","happy","right"};
int i = (int)(Math.random() * 3);
int len = word[i].length();
int temp = 0,count = 0,index = 0;
//把字符串转换成char类型的
char[] a = word[i].toCharArray();
while(temp < len) {
System.out.print("Enter a letter in word *****:");
String ch1 = input.next();
char ch2 = ch1.charAt(0);
for(int k = 0;k < len;k++) {
if(ch2 == a[k]) {
index = k;
switch(index) {
case 0:System.out.println("Enter a letter in word " + a[0] + "****");break;
case 1:System.out.println("Enter a letter in word " + "*" + a[1] +"***");break;
case 2:System.out.println("Enter a letter in word " + "**" + a[2] + "**");break;
case 3:System.out.println("Enter a letter in word " + "***" + a[3] + "*");break;
case 4:System.out.println("Enter a letter in word " + "****" + a[4]);break;
}
temp++;
}
}
count++;
}
System.out.print("要猜测的单词为:" + word[i] + " , " + " 你错了" + count + "次");
input.close();
}
}
我的计算猜错次数怎么弄都不对头
求解救