- import java.util.*;
- class guessNumb {
- public static void main(String[] args) {
- int rightNum=(int)(Math.random()*100)+1;
- System.out.println(rightNum);
- while(true){
- System.out.println("请输入一个100以内的正整数");
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
-
- if(num==rightNum){
- System.out.println("恭喜你猜对了"+"再来一发?Y/N");
- Scanner sc1=new Scanner(System.in);
- if(sc1.next().equalsIgnoreCase("Y")){
- rightNum=(int)(Math.random()*100)+1;
- System.out.println(rightNum);
- continue ;
- }else break;
- }
- else if (num<rightNum)
- {
- System.out.println("你输入的数小了");
- }
- else if (num>rightNum)
- {
- System.out.println("你输入的数大了");
- }
- }
-
- }
- }
复制代码 |
|