Skip to content

Commit 22961f3

Browse files
committed
feat: Copy elements from one array to another using loop
🧠 Logic: - Initializes an array `A` with 10 integers. - Creates a new array `B` of the same size. - Copies each element from `A` to `B` using a for loop. - Prints the contents of array `B` using an enhanced for-loop. Signed-off-by: Somesh diwan <[email protected]>
1 parent 720bed6 commit 22961f3

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
/*Copy array. one array to another array*/
1+
/*Copy array. One array to another array*/
22

3-
public class CopyingArray
4-
{
5-
public static void main(String[] args)
6-
{
3+
public class CopyingArray {
4+
public static void main(String[] args) {
75
int A[]={8,6,10,9,2,15,7,13,14,11};
86

97
int B[]=new int[10];
108

11-
for(int i=0;i<A.length;i++)
12-
{
9+
for(int i=0;i<A.length;i++) {
1310
B[i]=A[i];
1411
}
1512

16-
for(int x:B)
17-
{
13+
for(int x:B) {
1814
System.out.print(x+",");
1915
}
2016
}
21-
}
17+
}

0 commit comments

Comments
 (0)