猜数游戏

来源:互联网 发布:plc模块化编程实例 编辑:程序博客网 时间:2024/06/10 00:31
package hello;import java.util.Scanner;public class Hello { public static void main(String[] args) {  Scanner in = new Scanner(System.in);  int number;  int count=0;  int a;  number=(int)(Math.random()*100+1);    //1到100的随机值;  do  {   a=in.nextInt();   count ++;   if(a>number)   {    System.out.println("偏大啦");   }   else if(a<number)   {    System.out.println("偏小啦");   }  }while(a!=number);  System.out.print("猜对啦,猜了"+count+"次喔"); }}
0 0
原创粉丝点击