首页 > 代码库 > 猜数游戏-flag的运用
猜数游戏-flag的运用
package my;
import java.util.Scanner;
public class MyJava {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
int[] sum = {10,5,8,20,59,42,64};
System.out.println("猜数游戏开始");
System.out.println("请输入一个数:");
boolean flag = false;
do {
int value = http://www.mamicode.com/input.nextInt();
for (int i = 0; i < sum.length; i++) {
if (sum[i]==value) {
flag = true;
break;
}
}
if (flag) {
System.out.println("恭喜你!猜对了");
}else {
System.out.println("请重试!");
}
} while (!flag);
}
}
猜数游戏-flag的运用