public class MathRandom{
public static int GetEvenNum(double a,double b){
int s = (int)a +(int)(Math.random()*(b-a));
if(s%2==0){
return s;
}else
return s+1;
}
public static void For(double a,double b){
for(int i=1;i<=6;i++){
System.out.println("s" + i + "=" + GetEvenNum(a,b));
}
System.out.println();
}
public static void main(String args[]){
For(1,1000);
}
}
问题是让在1-1000的区间产生6个随机数 并且求出他们的和 我已经把随机数都求出来了 但是求和想了半天也没想出来该怎么弄,求大神给指教下,谢谢!