the following program uses 2 arrays a & b of sizes m & n, both the arrays take values from user. third array is of size m+n. i hv to merge these two arrays into third one. but becoz of 1 error i m unable to do this. i hv tried a lot to solve this error.
i had shown u error by pointing on it.

package arrays;
import java.io.*;

class arrays
{
  public static void main(String args[])  throws Exception
  {
      DataInputStream ds= new DataInputStream(System.in);
      BufferedReader br= new BufferedReader(new InputStreamReader(ds));
      int m,n,i;
      System.out.println("Enter the size of first array");
      m=Integer.parseInt(br.readLine());
      int a[]= new int[m];
      
      System.out.println("Enter"+m+"numbers");
      for( i=0;i<=m-1;i++)
      {
          a[i]=Integer.parseInt(br.readLine());
      }
     System.out.println("Enter the size of second array");
      n=Integer.parseInt(br.readLine());
      int b[]= new int[n];
      System.out.println("Enter"+n+"numbers");
      for( i=0;i<=n-1;i++)
      {
          a[i]=Integer.parseInt(br.readLine());
      }
      int z=m+n;
      int c[]= new int[z];
      for( i=0;i<=z-1;i++)
      {
         if(i=m)     // error, compiler says that here i&m should b of boolean type    but found int type. but without int type i cnt solve dis query
         {
             c[i]=a[i];
             
         }
         else
         {
            c[i]=b[i-m]; 
         }
      }
      for( i=0;i<=z-1;i++)
      {
          System.out.println(c[i]);
      }
  }
  
}

Recommended Answers

All 3 Replies

Take care to use the correct operator. '==' is for comparison.

as Ezzaral said:
'=' is for assignment
'==' is for equality

OMG, what a kind of mistake i hv done. thank you for recognizing this error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.