Java语言编写数字地雷游戏
Java源代码如下:
public class Demo01 { public static void main(String[] args) { game(); } static void game(){ int numRandom = new Random().nextInt(100)+1; Scanner sc = new Scanner(System.in); System.out.println("请输入你猜的数字:"); while(true) { int numScanner = sc.nextInt(); if(numRandom>numScanner){ System.out.println("数字小了,重新输入"); }else if(numRandom<numScanner){ System.out.println("数字大了,重新输入"); }else { System.out.println("恭喜你,猜中了"); break; } } } }