sphinx2001

Работа с массивами

Nov 2nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public class TestArray {
  2.  
  3.    public static void main(String[] args) {
  4.       double[] myList = {1.9, 2.9, 3.4, 3.5};
  5.  
  6.       // Вывести на экран все элементы массива
  7.       for (int i = 0; i < myList.length; i++) {
  8.          System.out.println(myList[i] + " ");
  9.       }
  10.       // Сумма элементов массива
  11.       double total = 0;
  12.       for (int i = 0; i < myList.length; i++) {
  13.          total += myList[i];
  14.       }
  15.       System.out.println("Сумма чисел массива: " + total);
  16.       // Нахождение среди элементов массива наибольшего
  17.       double max = myList[0];
  18.       for (int i = 1; i < myList.length; i++) {
  19.          if (myList[i] > max) max = myList[i];
  20.       }
  21.       System.out.println("Наибольший элемент: " + max);
  22.    }
  23. }
Add Comment
Please, Sign In to add comment