This is a Java program that takes two integer arrays as input from the user and creates a third array containing only the even numbers from the first two arrays. Here is a brief explanation of the code:
import java.util.Scanner; class EvenNum_ThridArray { public static void main(String[] args) { Scanner input =new Scanner(System.in); System.out.print("Enter the First Array Limit :"); int n =input.nextInt(); System.out.print("Enter the Second Array Limit :"); int m =input.nextInt(); int [] a =new int[n]; int [] b =new int[m]; int [] c =new int[100]; int k=0; for(int i=0;i<n;i++) { System.out.printf("Element of a[%d] :",i); a[i]=input.nextInt(); } for(int i=0;i<m;i++) { System.out.printf("Element of b[%d] :",i); b[i]=input.nextInt(); } for(int i=0;i<n;i++) { if(a[i]%2==0) { c[k]=a[i]; k++; } } for(int i=0;i<m;i++) { if(b[i]%2==0) { c[k]=b[i]; k++; } } System.out.print("\nEven Element Store in Third Array ...\n"); for(int i=0;i<k;i++) { System.out.printf("\nc[%d] = %d",i,c[i]); } } }
Enter the First Array Limit :5 Enter the Second Array Limit :3 Element of a[0] :1 Element of a[1] :2 Element of a[2] :3 Element of a[3] :4 Element of a[4] :5 Element of b[0] :6 Element of b[1] :7 Element of b[2] :8 Even Element Store in Third Array ... c[0] = 2 c[1] = 4 c[2] = 6 c[3] = 8
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions