我的第一个JAVA程序

来源:互联网 发布:成语接龙查询软件 编辑:程序博客网 时间:2024/06/13 03:24

猜数字:

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+"次");    }}
0 0