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

📄 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);
			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 + -