求大神帮写一下完整的java代码。题目要求见图片所示。在线等!
1个回答
展开全部
import java.util.Arrays;
import java.util.Scanner;
public class SmallGame {
public static void main(String args[]){
int StartNum = (int)(Math.random()*78)+99; //随机数
int GuessCount = 0;
int[] GuessNum = new int[20];
System.out.println("*******************小游戏****************");
System.out.println("****系统内置了一个99到177之间的随机数******");
String [] result ={"1 你太聪明了!","2~5 不错,再接再厉!","大于等于6 要努力啊!"};
while(true){
System.out.println("请输入你所猜的数值");
Scanner scan = new Scanner(System.in);
int read = scan.nextInt();
if(read>StartNum){
System.out.println("大了,再猜");
GuessNum[GuessCount]=read;
GuessCount++;
continue;
}else if(read<StartNum){
System.out.println("小了,再猜");
GuessNum[GuessCount]=read;
GuessCount++;
continue;
}else{
GuessNum[GuessCount]=read;
GuessCount++;
System.out.println("你总共用了"+GuessCount+"次猜中");
System.out.println("你所猜的数列如下");
System.out.print("{");
for(int i=0;i<GuessCount;i++){
System.out.print(GuessNum[i]+",");
}
System.out.print("}");
// System.out.println(Arrays.asList(GuessNum).toString());
System.out.println("\n本次猜测活动评价");
if(GuessCount==1){
System.out.println(result[0]);
}else if(GuessCount>6){
System.out.println(result[2]);
}else{
System.out.println(result[1]);
}
break;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询