今天在写一个比较简单的文字游戏的时候,突然发现一个重要的问题求解各位
代码如下
import java.util.Scanner;
import java.io.*;
public class Games {
public static void main(String[] args) {
System.out.println("欢迎来到小游戏专区!");
try{
Thread.sleep(1000);}
catch(Exception e){
System.exit(0);}
System.out.println("游戏正在初始化");
int coin=1000;
int choice,highest,ans,yans,f1,h,l,times;
System.out.println("Int类型加载完毕(1/3)");
Scanner scanner=new Scanner(System.in);
System.out.println("Scanner类型加载完毕(2/3)");
String Copyright="Sky Group(c)2018";
System.out.println("版权声明结束(3/3)");
System.out.println("有3个小游戏,请选择:1:猜数 2:** 3:投骰子");
try{
Thread.sleep(1000);}
catch(Exception e){
System.exit(0);}
System.out.print("请输入数字:");
choice=scanner.nextInt();
while(true){
if(choice==1){
System.out.println("请输入范围");
highest=scanner.nextInt();
while(highest<100){
System.out.println("注意:最高值不能小于100");
System.out.print("再次输入:");
highest=scanner.nextInt();
}
f1=(int)Math.round(Math.log(highest)/Math.log(2)*(15+Math.random()*10));
System.out.println("本次奖金:"+f1+"代币!");
ans=(int)Math.round(Math.random()*highest);
try{
Thread.sleep(1000);}
catch(Exception e){
System.exit(0);}
System.out.print("输入数字:");
h=highest;
l=0;
times=0;
yans=scanner.nextInt();
while(yans!=ans){
if(yans<ans){
l=yans;
System.out.println("太小了,-18代币!目前最高值:"+h+"目前最低值:"+l);
}
if(yans>ans){
h=yans;
System.out.println("太大了,-18代币!目前最高值:"+h+"目前最低值:"+l);
}
times=times+1;
System.out.print("再次输入:");
yans=scanner.nextInt();
}
System.out.println("回答正确!你使用了"+times+"次来回答,损耗"+times*18+"代币。");
System.out.println("本次奖金为"+f1+"代币");
System.out.print("正在结算");
for(int i =0 ;i < 5 ; i++){
System.out.print(".");
try{
Thread.sleep(300);}
catch(Exception e){
System.exit(0);}
}
System.out.println(".");
System.out.print("本次获得:");
if(times*18>f1){
setTextColor(255,0,0);
System.out.println(f1-times*18+"代币");
}
if(times*18<f1){
setTextColor(0,255,0);
System.out.println(f1-times*18+"代币");
}
if(times*18==f1){
System.out.println("0代币");
}
setTextColor(0,0,0);
coin=coin+f1-times*18;
try{
Thread.sleep(1000);}
catch(Exception e){
System.exit(0);}
System.out.println("剩余代币:"+coin);
}
//再次选择还未写!
}
}
}
错误信息: