Advertisement
Dido09

6 - Задача по Избор

May 8th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ZadachaPoIzbor {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scan = new Scanner(System.in);
  8.  
  9. String a = scan.nextLine();
  10. String[]chisla = a.split(" ");
  11. int[] b = new int [chisla.length];
  12. for(int i =0 ; i<chisla.length; i++) {
  13. b[i] = Integer.parseInt(chisla[i]);
  14. }
  15. int sum = sumArray(b);
  16. int max = maxNumber(b);
  17. int min = minNumber(b);
  18. double avg = averageArray(b);
  19.  
  20. System.out.println("Min: "+min);
  21. System.out.println("Max:" +max);
  22. System.out.println("Avg: "+avg);
  23. System.out.println("Sum: "+sum);
  24.  
  25.  
  26. }
  27. public static int sumArray(int[]arr) {
  28. int sum = 0;
  29. for(int i = 0; i<arr.length; i++) {
  30. sum += arr[i];
  31. }
  32. return sum;
  33. }
  34. public static double averageArray(int[]arr) {
  35. int sum = 0;
  36. for(int i = 0; i < arr.length;i++) {
  37. sum += arr[i];
  38. }
  39. double avg = (double) sum / arr.length;
  40. return avg;
  41. }
  42. public static int maxNumber(int[]arr) {
  43. int max = arr[0];
  44. for(int i =0; i < arr.length; i++) {
  45. if(arr[i]>max) {
  46. max = arr[i];
  47. }
  48. }
  49. return max;
  50. }
  51. public static int minNumber(int[]arr) {
  52. int min = arr[0];
  53. for(int i = 0; i<arr.length; i++) {
  54. if(arr[i] < min) {
  55. min = arr[i];
  56. }
  57. }
  58. return min;
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement