This Java program prompts the user to enter the limits for two arrays, then asks for input to fill the arrays. It then creates a third array and stores all odd elements from the first two arrays into the third array. Finally, it prints out the elements stored in the third array. Here's how the program works:
Overall, this program is a simple example of how to create and manipulate arrays in Java. It is useful for beginners who are just learning how to use arrays and loops in Java.
import java.util.Scanner; class OddNum_ThirdArray { 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==1) { c[k]=a[i]; k++; } } for(int i=0;i<m;i++) { if(b[i]%2==1) { c[k]=b[i]; k++; } } System.out.print("\nOdd 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 :3 Enter the Second Array Limit :5 Element of a[0] :1 Element of a[1] :2 Element of a[2] :3 Element of b[0] :4 Element of b[1] :5 Element of b[2] :6 Element of b[3] :7 Element of b[4] :8 Odd Element Store in Third Array ... c[0] = 1 c[1] = 3 c[2] = 5 c[3] = 7
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions