⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guess.java

📁 JAVA培训教程
💻 JAVA
字号:
import java.io.*;

public class Guess{
public static void main(String args[]){
	int m,n=0;
	String s;
	boolean again = false;
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader br = new BufferedReader(isr);
	do{
		m=(int)(Math.random()*101);
		System.out.println("请输入数值(1-100)");
		for(int i=0; ;i++){
			try{
				s = br.readLine();
				n = Integer.parseInt(s);
			}catch(IOException e){
				e.printStackTrace();	
			}
			
			if(n>m){
				System.out.println("偏大了,请继续:");
				continue;
			}else if(n<m){
				System.out.println("偏小了,请继续:");
				continue;
			}else {
				System.out.println("恭喜!"+ (i+1) + "次猜对!");
				break;
			}
		}
		try{
			System.out.println("是否重新开始(y/n)");
			s = br.readLine();
			again = s.equalsIgnoreCase("y")?true:false;
		}catch(IOException e){
			e.printStackTrace();	
		}
	}while(again);		
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -