本帖最后由 进军黑马 于 2015-6-28 23:54 编辑
- import java.util.Scanner;
- class RandomDemo1
- {
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
-
- while(true)
- {
- System.out.println("请输入1-100之间你要猜的数字");
- int num = (int)(Math.random()*100)+1;
-
- int a = sc.nextInt();
- if (a > 0 && a < 100)
- {
-
- if (a == num)
- {
- System.out.println(a+"..."+num+"恭喜您猜中了,请到苍井空处领取我们的Surprise");
-
- continue;
- }
- else if (a > num)
- {
- System.out.println(a+"..."+num+"不好意思你猜大了,再接再励哦");
- continue;
- }
- else if (a < num)
- {
- System.out.println(a+"..."+num+"不好意思你猜小了,再接再励哦");
-
- continue;
- }
- }else{
- System.out.println("您输入的数字有误,本次服务即将结束");
- break;
- }
-
- }
-
- }
- }
复制代码
|
|