×
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
5807    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.
Swami Vivekananda
Education is the manifestationof the perfection already in man.
Swami Vivekananda
3300
75.02
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     52290
25/06/2018     44059
01/01/2018     42982
28/06/2017     40718
02/08/2017     39572
01/08/2017     33742
06/07/2017     33558
15/05/2017     32834
14/07/2017     29127
11/09/2018     29119
softetechnologies