-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMyArray.java
More file actions
41 lines (32 loc) · 1.11 KB
/
MyArray.java
File metadata and controls
41 lines (32 loc) · 1.11 KB
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
public class MyArray {
public static void main(String[] args) {
double[] myList = {6.7, 3.9, 4.8, 5.2};
//This will print all the elements
/*for (int i = 0; i < myList.length; i++){
System.out.println(myList[i] + " ");
//System.out.println(myList[i] ++);
//System.out.println("myList = " + myList[i]);
}*/
for (double elements: myList){
System.out.println(elements);
}
//Summing all elements
double total = 0;
for (int i = 0; i < myList.length; i++){
total += myList[i];
}
System.out.println("Total is " + total);
//Finding the largest element
double max = myList[0];
for (int i = 0; i < myList.length; i++){
if (myList[i] > max) max = myList[i];
}
System.out.println("Max is " + max);
//Finding the smallest elements
double min = myList[0];
for (int i = 0; i < myList.length; i++){
if (myList[i] < min) min = myList[i];
}
System.out.println("min is " + min);
}
}