×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Neon Numbers In Java - ICSE Examples WAP in java to accept a number (0 -999) and print it in words.
Common Elements In Array In Java - ICSE Examples - Java
5218    Arnab De    17/05/2018

Array program [Basic]

Write a program to make suitable use of Scanner Class and its functions to input N integers in two single dimensional arrays X[] and Y[]. create another array z[] that contains integers from arrays X[] and Y[] that are common in both. Print All Three Arrays.

Solution:  First of all declare Three Array. Populate first two array. now pick every elements of first array and search it in the second array. If any elements of first array found in the second array then put it in the third array. Now print the all three array.

softetechnologies
import java.util.*;
public class Common
{
 public static void main()
 {
     Scanner sc = new Scanner(System.in);
     System.out.println("enter 5 integers for the 1st array:");
     int x[] = new int[5];
     int i,k,j,p;
     for( i = 0 ; i<5 ; i++)
     {
         x[i]=sc.nextInt();
        }
     System.out.println("enter 5 integers for the 2nd array:");
     int y[] = new int[5];
     for( k = 0 ; k<5 ; k++)
     {
         y[k]=sc.nextInt();
        } 
     int z[] = new int[10];
     k=0;
     for(j=0 ; j<5 ; j++)
     {
         for(p=0 ; p<5 ; p++)
         {
             if(x[j]==y[p])
             {
                 z[k++]=x[j];
             }
         }
     }
     System.out.println("X[] Array : ");
     for(j=0 ; j<5 ; j++)
     {
         System.out.print(x[j] + " ");
     }
     System.out.println("\nY[] Array : ");
     for(j=0 ; j<5 ; j++)
     {
         System.out.print(y[j] + " ");
     }
     System.out.println("\nZ[] Array : ");
     for(p=0;p
softetechnologies

Output

enter 5 integers for the 1st array:
12
23
34
45
56
enter 5 integers for the 2nd array:
21
23
434
54
56

X[] Array :
12 23 34 45 56
Y[] Array :
21 23 434 54 56
Z[] Array :
23 56

Neon Numbers In Java - ICSE Examples WAP in java to accept a number (0 -999) and print it in words.
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Albert Einstein
Unthinking respect for authority is the greatest enemy of truth.
Albert Einstein
6161
62.02
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     45778
25/06/2018     37974
01/01/2018     37713
28/06/2017     35687
02/08/2017     34345
01/08/2017     28666
06/07/2017     28418
15/05/2017     27968
14/07/2017     23776
11/09/2018     22613
softetechnologies