猜数游戏

来源:互联网 发布:贵州卫计委网络直报 编辑:程序博客网 时间:2024/06/05 02:59
package work;import java.util.Scanner;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner in=new Scanner(System.in);int a;int number=(int)(Math.random()*100+1);int count = 0;do{a=in.nextInt();count=count+1;if(a>number){System.out.println("大了");}else if(a<number){System.out.println("小了");}} while(a!=number);System.out.println("恭喜你猜对了,猜了:"+count+"次");}}

0 0
原创粉丝点击