Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b87b0da

Browse files
🍵
1 parent ed52a19 commit b87b0da

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎challenge26.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
3+
// Create a program to find the sum and average of all elements in an array.🚀
4+
public class challenge26 {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
8+
9+
System.out.println("Welcome to Array sum and Average");
10+
System.out.print("Please enter the number of element: ");
11+
int size = sc.nextInt();
12+
int[] num = new int[size];
13+
int i = 0;
14+
while (i < size) {
15+
System.out.println("Please enter element no: " + (i + 1) + ": ");
16+
num[i] = sc.nextInt();
17+
i++;
18+
}
19+
int sum = 0;
20+
for (int j = 0; j < size; j++) {
21+
sum += num[j];
22+
}
23+
double average = (double) sum / size;
24+
System.out.println("The sum of the array is: " + sum);
25+
System.out.println("The average of the array is: " + average);
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /