首页 练字文章 自动猜数代码

自动猜数代码

2022-05-06 15:14  浏览数:392  来源:2940164968    

import java.util.Random;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static public void main(String[] args) {
Random r = new Random();
int rdm = r.nextInt(100) + 1;
int min = 0;
int max = 101;
int num = (min + max) / 2;
while (true) {
System.out.print("Please enter the number you guess:");
int suspect = num;
if (suspect == rdm) {
System.out.println("Congratulations on your guess!");
break;
} else if (suspect < rdm) {
System.out.println("Small");
min = suspect;
} else if (suspect > rdm) {
System.out.println("Big");
max = suspect;
}
System.out.println(suspect);
num = (min + max) / 2;
}
}



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)