开发了一个程序,功能如下: 获取2~32之间的6个整数,并取得这6个偶数的和。
本例中引用了Math.random(),但是实际上实现的是Random.nextDouble()。 只是对于一般的使用random的情况,较Random类,我们习惯使用Math.random() mainly because it si simpler to use
/*** 开发了一个程序,功能如下:* 获取2~32之间的6个整数,并取得这6个偶数的和。* <p>* 本例中引用了Math.random(),但是实际上实现的是Random.nextDouble()。* 只是对于一般的使用random的情况,较Random类,我们习惯使用Math.random() mainly because it is simpler to use* @author HAN**/
public class DataTreatementClassApps {public static void main(String[] args) {int i=0;int sum=0;while(i<6){int a=(int) (2+Math.random()*30); if (a%2==0){ //取余方法System.out.println(a);sum=sum+a;i++;}}System.out.println("六个偶数的和:"+sum);}}