Find Missing numbers between 1 to 100 in sorted array in java


In this core java programming tutorial we will write a program to find Missing numbers between 1 to 100 in sorted array in java.

Missing numbers between 1 to 100 in sorted array in java.


Suppose given sorted array : 3 5 8 44
Numbers missing between 1 to 100 in array :  1 2 4 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100




Full Program/SourceCode/ example to find Missing numbers between 1 to 100 in sorted array in java >
/** Copyright (c), AnkitMittal www.JavaMadeSoEasy.com */
public class FindMissingNumberInSortedArrayExample{
   static int ar[]={3,5,8,44}; //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 between 1 to 100 in array :  ");
         
          int j=0;
          for(int i=1;i<=100;i++){
                 if(j<ar.length && i==ar[j])
                       j++;
                 else
                       System.out.print(i+" ");
                
          }
         
   }
  
}
/*OUTPUT
given array(already sorted): 3 5 8 44
Numbers missing between 1 to 100 in array :  1 2 4 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
*/

So In this core java programming tutorial we wrote a program on how to find Missing numbers between 1 to 100 in sorted array in java.


Previous program                                                                  Next program



Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>







No comments:

Post a Comment