java返回一个 low 到 high的随机整数 (包括low和high).Which /* expression */ will always return a value that satisfies the postcondition?( )(A) (int) (Math.random() * high) + low;(B) (int) (Math.random() * (high - low)) + low;(C) (int) (Mat

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 01:22:04
java返回一个 low 到 high的随机整数 (包括low和high).Which /* expression */ will always return a value that satisfies the postcondition?( )(A) (int) (Math.random() * high) + low;(B) (int) (Math.random() * (high - low)) + low;(C) (int) (Mat

java返回一个 low 到 high的随机整数 (包括low和high).Which /* expression */ will always return a value that satisfies the postcondition?( )(A) (int) (Math.random() * high) + low;(B) (int) (Math.random() * (high - low)) + low;(C) (int) (Mat
java返回一个 low 到 high的随机整数 (包括low和high).
Which /* expression */ will always return a value that satisfies the postcondition?( )
(A) (int) (Math.random() * high) + low;
(B) (int) (Math.random() * (high - low)) + low;
(C) (int) (Math.random() * (high - low + 1)) + low;
(D) (int) (Math.random() * (high + low)) + low;

java返回一个 low 到 high的随机整数 (包括low和high).Which /* expression */ will always return a value that satisfies the postcondition?( )(A) (int) (Math.random() * high) + low;(B) (int) (Math.random() * (high - low)) + low;(C) (int) (Mat
public int getRandom(int low,int high){
    Random r=new Random();
    int rand=r.nextInt(high-low+1);//产生一个0到high-low的整数
    return rand+low;
}