We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ed52a19 commit b87b0daCopy full SHA for b87b0da
challenge26.java
@@ -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
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments