-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayInputAndAverage.java
More file actions
40 lines (28 loc) · 996 Bytes
/
ArrayInputAndAverage.java
File metadata and controls
40 lines (28 loc) · 996 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
package com.company;
import java.util.Scanner;
public class Main {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int[] myIntegers = getIntegers(5);
for (int i = 0; i < myIntegers.length; i++) {
System.out.println("Element " + i + " typed values: " + myIntegers[i]);
}
System.out.println("The average " + getAvarage(myIntegers));
}
public static int[] getIntegers(int number) {
System.out.println("Enter " + number + " integer value. \r");
int[] values = new int[number];
for (int i = 0; i < values.length; i++) {
values[i] = scanner.nextInt();
}
return values;
}
public static double getAvarage(int[] array) {
int sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
}
double avarage = (double)sum / (double)array.length;
return avarage;
}
}