赞
踩
import java.util.Random; import java.util.Scanner; public class Main {public static void main(String[] args) { Scanner scan = new Scanner(System.in); Random random = new Random(); int rand = random.nextInt(100); while(true) { System.out.println("请输入一个数字:"); int num = scan.nextInt(); if(num>rand) { System.out.println("你猜的大了"); } else if(num==rand) { System.out.println("猜对了"); break;//猜对后跳出循环 } else{ System.out.println("猜小了"); } } System.out.println("游戏结束!"); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。