Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.RoundingMode;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner userInput = new Scanner(System.in);
  9. short n = userInput.nextShort();
  10. double min=Integer.MAX_VALUE;
  11. double max=Integer.MIN_VALUE;
  12. double sum=0;
  13. double avg=0;
  14. for (int i = 0; i <n ; i++) {
  15. double b=userInput.nextDouble();
  16. if(b>max){
  17. max=b;
  18. }if (b<min){
  19. min=b;
  20. }sum+=b;
  21. }
  22. avg=sum/n;
  23. BigDecimal rounded = BigDecimal.valueOf(avg);
  24. rounded = rounded.setScale(2, RoundingMode.HALF_UP);
  25. System.out.println("min=" + min);
  26. System.out.println("max=" + max);
  27. System.out.println("sum="+sum);
  28. System.out.println("avg="+avg);
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement