This is a Java program that creates a copy of an array entered by the user. Here is a step-by-step explanation of how the program works:
import java.util.Scanner; class Array_Copy { public static void main(String[] args) { Scanner input =new Scanner(System.in); System.out.print("Enter the Array Limit :"); int l =input.nextInt(); int [] a =new int[l]; int [] c =new int[l]; int sum = 0; for(int i=0;i<l;i++) { System.out.printf("Element of a[%d] :",i); a[i]=input.nextInt(); } for(int i=0;i<l;i++) { c[i] = a[i]; } System.out.print("\nOriginal Array Elements..."); for(int i=0;i<l;i++) { System.out.printf("\na[%d] = %d",i,a[i]); } System.out.print("\n\nCopy Array Elements one to Another Array..."); for(int i=0;i<l;i++) { System.out.printf("\nc[%d] = %d",i,c[i]); } } }
Enter the Array Limit :5 Element of a[0] :5 Element of a[1] :4 Element of a[2] :3 Element of a[3] :2 Element of a[4] :1 Original Array Elements... a[0] = 5 a[1] = 4 a[2] = 3 a[3] = 2 a[4] = 1 Copy Array Elements one to Another Array... c[0] = 5 c[1] = 4 c[2] = 3 c[3] = 2 c[4] = 1
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions