Java program to copy an array by iterating the array (copy from one array into another array)

import java.util.*;
public class Sorting {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
b[i]=a[i];
}
for(int i=0;i<n;i++)
{
System.out.println(" "+b[i]+" ");
}


}
}
i/p: 5
1 2 3 4 5
o/p: 1
 2
 3
 4
 5

No comments:

Post a Comment