-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
32 lines (28 loc) · 918 Bytes
/
Main.java
File metadata and controls
32 lines (28 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.yurii.salimov.lesson04.task04;
import java.util.Random;
/**
* 4.4 Задача
*
* Дано массив из 10 целых чисел. Вывести на экран
* сумму всех его элементов кроме первого и
* последнего.
*
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
*/
public class Main {
public static void main(String[] args) {
final int length = 10;
final int[] array = randomArray(length);
final ArraySum arraySum = new ArraySumImpl(array);
final int sum = arraySum.sum(1, length - 1);
System.out.println(sum);
}
private static int[] randomArray(final int length) {
final int[] array = new int[length];
final Random random = new Random();
for (int i = 0; i < length; i++) {
array[i] = random.nextInt();
}
return array;
}
}