猜数字游戏,并显示答案边界值 import java.util.Random; import java.util.Scanner; public class GuessNumber { public static void main(String[] args) { Random ran=new Random(); int num=ran.nextInt(100); //System.out.println(num);//作弊 Scanner scan = new Scanner(System.in); System.out.println("猜数字游戏,请输入一个0~100的合法数字:"); int big=100,small=0; while(true){ System.out.println("输入一个数字"); int guess=scan.nextInt(); if(guess==-1){ System.out.println("游戏结束") break; }else if(guess<0||guess>100){ System.out.println("输入数字不合法,请重新输入:"); }else if(guessnum){ big=guess; System.out.println("猜错了,范围在"+small+"~"+big+"之间"); }else{ System.out.println("恭喜你答对了"); break; } } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)