- import java.util.*;
- class GuessNumber
- {
- public static void main(String[] args)
- {
- int num=(int)(Math.random()*100)+1;
- Scanner sc=new Scanner(System.in);
- for(;;)//while(true)
- {
- System.out.println("请输入1-100的随机数:");
- int r=sc.nextInt();
- if (r>num)
- {
- System.out.println("您猜的大了");
- }
- else if (r<num)
- {
- System.out.println("您猜的小了");
- }
- else
- {
- System.out.println("您猜中了");
- break;
- }
-
- }
- }
- }
复制代码
|
|