这个猜数游戏中怎么将for循环的语句换成while循环语句


```import java.util.Random;
import java.util.Scanner;
public class Chenwei_Guessnumebr{
static int w = 8;
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Random ran = new Random();
        int num = ran.nextInt(100)+1;   
        for(;;){                    
            System.out.println("1.开始猜数");
            System.out.println("2.游戏参数设置");
            System.out.println("9.退出");
            Scanner sc=new Scanner(System.in);      
            String choo =sc.next();
            if (!choo.equals("1")&&!choo.equals("2")&&!choo.equals("9")){       //if条件语句 三种条件,限制情况.
                System.out.println("非法数据");
            }
            else 
            {
                if (choo.equals("1"))
                {
                    int t = 1;                  
                    for (t=1;t<w;t=t+1)             
                    {           
                        System.out.println("请输入你想猜测的数字");
                        Scanner scs=new Scanner(System.in);     
                        int n = scs.nextInt();  
                        if (n>num)
                        {
                            System.out.println("猜的数字大了.");
                        }
                        else if (n<num)
                        {
                            System.out.println("猜的数字小了.");
                        }
                        else{
                            System.out.println("恭喜你猜对了,你的战斗力是x%" );       //  ☆“缺一个计算战斗力的式子”
                            break;
                        }
                    }
                        if(t > w)           //t(猜测次数)超过了w(设置的总次数)
                        {           
                            System.out.println("超过次数,尚需努力");
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                 if(choo.equals("2")){          
                    System.out.println("请选择难度:");
                    System.out.println("1.简单");
                    System.out.println("2.一般");
                    System.out.println("3.困难");
                    Scanner scs = new Scanner(System.in);
                    int u = scs.nextInt();
                    if (u==1)
                    {
                        w=8;        //次数为8(简单)
                    }
                    else if (u==2)
                    {
                        w=6;        //次数为6(一般)
                    }
                    else
                    {
                        w=4;        //次数为4(困难)
                    }
                }
                else
                {
                    break;
                    }
            }
        }
    }

同时缺少一个计算战斗力的式子
就是在答对的时候
“恭喜你猜对了,你的战斗力是x%"(x=1-n/8,n是猜中时的次数-1)

for(;;)
修改为
while(true)即可

System.out.println("恭喜你猜对了,你的战斗力是x%" );

->
System.out.println("恭喜你猜对了,你的战斗力是" + 1- (t - 1) / (float)8+ "%" );

public class Main {

    static int w = 8;
    static Scanner s = null; 
    public static void main(String[] args) {
        s = new Scanner(System.in);
        Random ran = new Random();
        int num = ran.nextInt(100)+1;  
        while(true){
            System.out.println("1.开始猜数\n"
                             + "2.游戏参数设置\n"
                             + "9.退出");
            int c = s.nextInt();
            switch(c){
                case 1:
                    int t = 0;
                    while(t++ < w){
                        System.out.println("请输入你想猜测的数字");
                        int n = s.nextInt();
                        if (n == num){
                            System.out.println(String.format("恭喜你猜对了,你的战斗力是 %f %%", (1-t/8.0)*100)); 
                            break;
                        }
                        System.out.println(String.format("猜的数字%s了.", n>num?"大":"小"));
                    }
                    if(t > w){           
                        System.out.println("超过次数,尚需努力");
                    }
                    break;
                case 2:
                    System.out.println("请选择难度:\n"
                                     + "1.简单\n"
                                     + "2.一般\n"
                                     + "3.困难\n");
                    int ch = s.nextInt();
                    w = w - 2*(ch-1);
                    break;
                case 9:
                    System.exit(0); 
                    break;
                default:
                    System.out.println("非法数据");
                    break;
            }

        }
    }


}