- package com.heima.text1;
- import java.util.Scanner;
- //我要获取一个1-100之间的随机数,肿么办?
- //Math类下的方法random();
- class Test2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个0-100之间的整数");
-
- int guessNum = (int)(Math.random()*100)+1;
- while(true){
- int result = sc.nextInt();
- if(result<guessNum){
- System.out.println("你输入的数字小了");
-
- }else if(result>guessNum){
- System.out.println("你输入的数字大了");
-
- }else{
- System.out.println("你猜中了");
- break;
- }
- }
-
- }
- }
复制代码 |
|