Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner userInput = new Scanner(System.in);
- short n = userInput.nextShort();
- double min=Integer.MAX_VALUE;
- double max=Integer.MIN_VALUE;
- double sum=0;
- double avg=0;
- for (int i = 0; i <n ; i++) {
- double b=userInput.nextDouble();
- if(b>max){
- max=b;
- }if (b<min){
- min=b;
- }sum+=b;
- }
- avg=sum/n;
- BigDecimal rounded = BigDecimal.valueOf(avg);
- rounded = rounded.setScale(2, RoundingMode.HALF_UP);
- System.out.println("min=" + min);
- System.out.println("max=" + max);
- System.out.println("sum="+sum);
- System.out.println("avg="+avg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement