java 入门小程序

来源:百度知道 编辑:UC知道 时间:2024/05/27 03:20:46
编写程序,声明一个double型变量,并任意赋值,然后判断该书是否在1到10000之间,根据结果输出下面其中一行结果(X需用实际的数值代替):
The number X is between 1 and 10000.
The number X is not between 1 and 10000.

public class Test{
public static void main(String[] args){
estimate(Math.random() * 20000);// 随进获得一个数字,大于0小于20000
}

private static void estimate(double num){
String result = "The number " + num + " is not between 1 and 10000";

// 判断是否在1到10000之间
if(num - 1 >= 0){
if(num - 10000 <= 0){
result = "The number " + num + " is between 1 and 10000";
}
}

System.out.println(result);
}
}