Advertisement
Guest User

Untitled

a guest
Feb 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class MinMaxSumAvarage{
  3. public static void main(String[] args) {
  4. Scanner in= new Scanner(System.in);
  5. int N=in.nextInt();
  6. float[] a = new float[N];
  7. float max=-1000000;
  8. float min=1000000;
  9. float sum=0;
  10. for(int i=0;i<N;i++){
  11. a[i]=in.nextFloat();
  12. if(max<a[i]){
  13. max=a[i];
  14. }
  15. if(min>a[i]){
  16. min=a[i];
  17. }
  18. sum+=a[i];
  19. }
  20. float avg=0;
  21. float sumavg=0;
  22. for(int i=0;i<N;i++){
  23. sumavg+=a[i];
  24. }
  25. avg=sumavg/N;
  26. System.out.print("min=");
  27. System.out.printf("%.2f\n",min);
  28. System.out.print("max=");
  29. System.out.printf("%.2f\n",max);
  30. System.out.print("sum=");
  31. System.out.printf("%.2f\n",sum);
  32. System.out.print("avg=");
  33. System.out.printf("%.2f\n",avg);
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement