谁给个“猜猜猜”的java程序?

来源:百度知道 编辑:UC知道 时间:2024/07/07 06:42:01
猜数字游戏先产生一个0-100的随机数。弹出输入框输入猜的数字。如果猜对了,提示对了,如果猜错了,弹出输入框提示偏大或偏小并继续猜。猜错5次后程序结束。用eclipse编。

import java.io.*;
public class Cai {
public static void main(String[] args) throws IOException{
boolean bool=false;
int count=0;
while(!bool){
int ss =(int)(0+Math.random()*(100-0+1));
System.out.println("这个随机数是"+ss);
System.out.println("请输入数字");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int name =Integer.parseInt( reader.readLine());
if(name==ss){
System.out.print("恭喜你猜对了");bool=true;
}else{
count++;
if(name>ss){
System.out.println("你猜的数太大了");

}
if(name<ss){
System.out.println("你猜的数太小了");
}
if(count==5){
System.out.println("你猜错的次数为"+count+"次 \t 将终止你的猜测");
bool=true;
}
}
}
}

}

import java.awt.BorderLayout;
import javax.swing.