Home > Back-end >  Could you tell me how to do bosses this problem?
Could you tell me how to do bosses this problem?

Time:10-02

Programming: using the Random class generates between 5 ~ 30 1 (including Random integers, 1 and 30) and find out the maximum and minimum value and average value of output,

CodePudding user response:

 Random r=new Random (); 
Int [] arr=new int [5].
For (int I=0; i<5; I++) {
Arr=[I] r.n extInt (31).
System. The out. Println (arr [I]);
}
Int Max=arr [0];
For (int j=0; JIf (Max & lt; Arr [j]) {
Max=arr [j];
}
}
System. The out. Println (Max);
Int min=arr [0];
For (int j=0; JIf (min & gt; Arr [j]) {
Min=arr [j];
}
}
System. The out. Println (min);

int sum=0;
For (int k=0; KThe sum +=arr [k].
}
Double d=sum/arr. Length;
BigDecimal b=new BigDecimal (sum);
C=new BigDecimal BigDecimal (arr. Length);
System. The out. Println (d);
System. The out. Println (b.d ivide (c, 4, BigDecimal. ROUND_HALF_UP). DoubleValue ());
System.out.println(sum);
System. The out. Println (arr. Length);
  • Related