INTERCHANGING OF ARRAY ELEMENTS
import java.util.Scanner;class inter_Array
{
public static void main (String args[])
{
Scanner sc = new Scanner(System.in);
int j,i;
System.out.print("Enter the size of array");
j=sc.nextInt();
int a[] = new int [j];
int b[] = new int [j];
int c[] = new int [j];
System.out.print("Enter the elements of first array");
for (i=0;i<j;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Enter the 2nd elements of array");
for(i=0;i<j;i++)
{
b[i]=sc.nextInt();
}
for(i=0;i<j;i++)
{
c[i]=a[i];
}
for(i=0;i<j;i++)
{
a[i]=b[i];
}
for( i=0;i<j;i++)
{
b[i]=c[i];
}
System.out.println("After exchange array elements");
System.out.println("Elements of first array are");
for(i=0;i<j;i++)
{
System.out.print(a[i]+" ");
}
System.out.println("Elements of second array are");
for(i=0;i<j;i++)
{
System.out.print(b[i]+" ");
}
}
}
0 Comments