```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.開始猜數(shù)");
System.out.println("2.游戲參數(shù)設(shè)置");
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("非法數(shù)據(jù)");
}
else
{
if (choo.equals("1"))
{
int t = 1;
for (t=1;t<w;t=t+1)
{
System.out.println("請輸入你想猜測的數(shù)字");
Scanner scs=new Scanner(System.in);
int n = scs.nextInt();
if (n>num)
{
System.out.println("猜的數(shù)字大了.");
}
else if (n<num)
{
System.out.println("猜的數(shù)字小了.");
}
else{
System.out.println("恭喜你猜對了,你的戰(zhàn)斗力是x%" ); // ☆“缺一個計算戰(zhàn)斗力的式子”
break;
}
}
if(t > w) //t(猜測次數(shù))超過了w(設(shè)置的總次數(shù))
{
System.out.println("超過次數(shù),尚需努力");
break;
}
else
{
break;
}
}
}同時缺少一個計算戰(zhàn)斗力的式子
就是在答對的時候
“恭喜你猜對了,你的戰(zhàn)斗力是x%"(x=1-n/8,n是猜中時的次數(shù)-1)
2 回答

揚帆大魚
TA貢獻1799條經(jīng)驗 獲得超9個贊
for(;;)
修改為
while(true)即可
System.out.println("恭喜你猜對了,你的戰(zhàn)斗力是x%" );
->
System.out.println("恭喜你猜對了,你的戰(zhàn)斗力是" + 1- (t - 1) / (float)8+ "%" );
添加回答
舉報
0/150
提交
取消