Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

In an array 1-100 numbers are stored,one number is missing how to find it in java with user input?

user-image
Question added by vaibhav gunjal
Date Posted: 2016/09/13
Noman Khawaja
by Noman Khawaja , Ex - System Analyst / Java Developer , Systems Advisory Services

public class FindMissingNumberInSortedArrayExample

{   

static int ar[]={3,5,8,}; //given array      

public static void main(String[] args)

{          

displayMissing();         

}      

/*    * Method finds out missing number in given range.    */   

static public void displayMissing()

{                    

System.out.print("given array(already sorted): ");

         for (int j =0; j < ar.length; j++)

                System.out.print(ar[j] +" "); // display it

  System.out.print("\\nNumbers missing between1 to in array :  ");

   int j=0;

   for(int i=1;i<=;i++)

   {                 

    if(j<ar.length && i==ar[j])

        j++;

    else                       

      System.out.print(i+" ");

     }

    }

  }

Sort the array first then check the next number is old one + 1

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.