diff --git a/week1/day2/classroom/arrays/MissingElementInAnArray.java b/week1/day2/classroom/arrays/MissingElementInAnArray.java index 1fddea5..0c56075 100644 --- a/week1/day2/classroom/arrays/MissingElementInAnArray.java +++ b/week1/day2/classroom/arrays/MissingElementInAnArray.java @@ -6,11 +6,17 @@ public static void main(String[] args) { // Here is the input int[] arr = {1,2,3,4,7,6,8}; - // Sort the array + // Sort the array + + Arrays.sort(arr); // loop through the array (start i from arr[0] till the length of the array) - +for (int i=1;i<=arr.length;i++){ + if(i!=arr[i-1]); + System.out.println( "Missing no is"+ i); + break; +} // check if the iterator variable is not equal to the array values respectively // print the number @@ -22,4 +28,4 @@ public static void main(String[] args) { } -} \ No newline at end of file +}