Skip to content

Commit ca7f4b7

Browse files
committed
Task1.1 added
1 parent f002cfd commit ca7f4b7

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎Answers/src/Task1_1.java‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.Scanner;
2+
3+
public class Task1_1 {
4+
5+
public static void main(String[] args) {
6+
7+
try (Scanner scan = new Scanner(System.in)) {
8+
System.out.print("Enter array length: ");
9+
int size = scan.nextInt();
10+
System.out.println();
11+
int arrayA[] = new int[size];
12+
System.out.println("Insert array elements:");
13+
14+
for (int i = 0; i < size; i++) {
15+
arrayA[i] = scan.nextInt();
16+
}
17+
18+
System.out.println();
19+
System.out.println("Enter divider: ");
20+
int divider = scan.nextInt();
21+
System.out.println();
22+
23+
int sum = 0;
24+
25+
for (int i = 0; i < size; i++) {
26+
if (arrayA[i] % divider == 0) {
27+
sum += arrayA[i];
28+
}
29+
}
30+
System.out.println("Sum of required elements is " + sum);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)