Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ZadachaPoIzbor {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String a = scan.nextLine();
- String[]chisla = a.split(" ");
- int[] b = new int [chisla.length];
- for(int i =0 ; i<chisla.length; i++) {
- b[i] = Integer.parseInt(chisla[i]);
- }
- int sum = sumArray(b);
- int max = maxNumber(b);
- int min = minNumber(b);
- double avg = averageArray(b);
- System.out.println("Min: "+min);
- System.out.println("Max:" +max);
- System.out.println("Avg: "+avg);
- System.out.println("Sum: "+sum);
- }
- public static int sumArray(int[]arr) {
- int sum = 0;
- for(int i = 0; i<arr.length; i++) {
- sum += arr[i];
- }
- return sum;
- }
- public static double averageArray(int[]arr) {
- int sum = 0;
- for(int i = 0; i < arr.length;i++) {
- sum += arr[i];
- }
- double avg = (double) sum / arr.length;
- return avg;
- }
- public static int maxNumber(int[]arr) {
- int max = arr[0];
- for(int i =0; i < arr.length; i++) {
- if(arr[i]>max) {
- max = arr[i];
- }
- }
- return max;
- }
- public static int minNumber(int[]arr) {
- int min = arr[0];
- for(int i = 0; i<arr.length; i++) {
- if(arr[i] < min) {
- min = arr[i];
- }
- }
- return min;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement