-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayAdder.java
More file actions
44 lines (30 loc) · 1.03 KB
/
ArrayAdder.java
File metadata and controls
44 lines (30 loc) · 1.03 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
42
43
44
import java.util.Scanner;
public class ArrayAdder {
public static void main(String[] args) {
//setting up the scanner
Scanner input = new Scanner(System.in);
//prompt user for input
System.out.println("What size array would you like?");
//store next inputed integer
int arraySize = input.nextInt();
//set up array to hold type double
double[] arr = new double[arraySize];
//for loop to populate the array
for(int i = 0; i < arraySize; i++) {
System.out.println("Please populate array: ");
arr[i] = input.nextDouble();
}
//double to store the accumulative array additions
double count = 0;
System.out.println("Your array is: ");
//for loop displaying contents and adding members
for(int i = 0; i < arraySize; i++) {
System.out.print(arr[i] + "\t");
count = count + arr[i];
}
//displaying the total to the user
System.out.println("\nThe sum total is: " + count);
//close scanner
input.close();
}//end method
}//end class