猜数字:
package hello;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int num;
num=(int)(Math.random()*100+1);//->[0,1)
System.out.println("请输入一个1~100的数字");
int a;
int count=0;
do
{
count++;
a=in.nextInt();
if(a>num)
System.out.println("太大了");
else if(a<num)
System.out.println("太小了");
}while(a!=num);
System.out.println("恭喜你猜对了,你一共猜了"+count+"次");
}
}