一个猜数小游戏

在零到一百猜数字,提醒你偏大或偏小,直到猜出正确数字。。

import java.util.*;
public class SetMath {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in  =new  Scanner(System.in);
		int number =(int) (Math.random()*100+1);
		int count=0;
		int a;
		do {
			a=in.nextInt();
			count+=1;
			if(a>number) {
				System.out.println("偏大");
			}
			else if(a<number) {
				System.out.println("偏小");
			}
		}
		while(a!=number);
		System.out.println("太棒了,你猜对了。你猜了:"+count+"次。");
	

	}

}
想起以前高中学概率时,那可爱的数学老师举起过的一个例子,嗯,挺想他的,特别是今天考试考砸后。

猜你喜欢

转载自blog.csdn.net/weixin_40980087/article/details/80933867