Skip to content

Commit 1f56cfa

Browse files
committed
feat: Accept array input from user and print even numbers
🧠 Logic: - Read the array size `n` from the user and create an array `A` of size `n`. - Accept `n` elements from the user using a for loop. - Traverse the array and check each element: - If the element is divisible by 2 (`A[i] % 2 == 0`), print it as an even number. Signed-off-by: Somesh diwan <[email protected]>
1 parent 8253cd1 commit 1f56cfa

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

Section8LoopAB/Loop 2.O/src/A2.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
import java.util.Scanner;
22

3-
class A2
4-
{
5-
public static void main(String[] args)
6-
{
3+
class A2 {
4+
public static void main(String[] args) {
75
Scanner sc = new Scanner(System.in);
86
int n;
97
System.out.println("Enter size of the Array");
108
n = sc.nextInt();
9+
1110
int [] A = new int[n];
1211
System.out.println("Enter n elements of");
1312

14-
for(int i =0; i<A.length; i++)
15-
{
13+
for(int i =0; i<A.length; i++) {
1614
A[i] = sc.nextInt();
1715
}
18-
1916
System.out.println("Even Numbers are: ");
20-
for(int i = 0; i<A.length; i++)
21-
{
22-
if(A[i]%2==0)
23-
{
17+
18+
for(int i = 0; i<A.length; i++) {
19+
if(A[i]%2==0) {
2420
System.out.println(A[i]);
2521
}
2622
}

0 commit comments

Comments
 (0)