-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays.java
More file actions
43 lines (30 loc) · 1013 Bytes
/
Arrays.java
File metadata and controls
43 lines (30 loc) · 1013 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
33
34
35
36
37
38
39
40
41
42
43
package javaIntroduction;
public class Arrays {
public static void main(String[] args) {
int[] array = {3, 4, 5, 1 , 10, 89, 7};
//display number of elements in the array
System.out.println("Length = "+array.length);
//product of all elements in the array of integers
int product = 1;
for(int i = 0; i < array.length; i++) {
product *= array[i]; //i = 0, 1,2 ... 4
}
System.out.println("Prodcut = "+product);
//sum of all elements in the array of integers
int sum = 0;
for(int i = 0; i < array.length; i++) {
sum += array[i]; //i = 0, 1,2 ... 4
}
System.out.println("Sum = "+sum);
//average of all elements in the array of integers
System.out.println("Avg = "+(sum / array.length));
//maximum of all elements in the array of integers
int max = array[0];
for(int i = 0; i < array.length; i++) {
if(array[i] > max) {
max = array[i];
}
}
System.out.println("Max = "+max);
}
}