public static void main(String[] args) { Random random=new Random(); int test=random.nextInt(100); System.out.println("请输入一个1-100的数字"); int num=0; int score=100; while(true) { ++num; Scanner sc=new Scanner(System.in); if(!sc.hasNextInt()){ if("quiet".equals(sc.next())){ System.out.println("你已成功退出游戏"); break; } else{ System.out.println("输入有误,请重新输入"); } }else{ int temp=sc.nextInt(); if(temp>test){ System.out.println("你猜大了"); continue; } else if(temp<test){ System.out.println("你猜小了"); continue; }else{ if(num==1){ System.out.println("你真聪明"); } System.out.println(num); System.out.printf("恭喜你猜对了,你的分数是%d%n",score-((num-1)*10)); break; } } } }
java实现猜数字游戏
最新推荐文章于 2024-10-16 16:34:42 发布