您的位置:首页 > 编程语言 > Java开发

【java】猜数字小游戏

2014-09-09 19:59 232 查看
package csdn.net;

import java.util.Random;

import java.util.Scanner;

public class lianxi3YX {

public static void main(String[] args) {

Random r = new Random();

int i, c = 1;

i = r.nextInt(9);

System.out.println("请猜10以内的数字:");

while (true) {

Scanner number = new Scanner(System.in);

int f = number.nextInt();

if (c <= 3) {

c = c + 1;

if (f > 0 && f < 10) {

if (i > f) {

System.out.println("小了");

} else if (i < f) {

System.out.println("大了");

} else {

System.out.println("猜对了");

break;

}

} else {

System.out.println("超出范围了,笨蛋!");

}

} else {

System.out.println("3次都猜不出来...,笨的和肖志旭似得呢!");

break;

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: