一个猜数小游戏
在零到一百猜数字,提醒你偏大或偏小,直到猜出正确数字。。
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+"次。");
}
}
还没有评论,来说两句吧...