谁给个“猜猜猜”的java程序?
来源:百度知道 编辑:UC知道 时间:2024/07/07 06:42:01
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.