Missing number program in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 3

Missing number program in java

20th Nov 2021, 6:22 PM
Durgvijay Maurya
11 Answers
+ 8
Vijay Maurya , ▪︎before we are going to help you, please present your attempt here.     if you haven't done a try by yourself so far, please do so. create your code in playground and post the link to it here. ▪︎please also provide a proper task description with sample of input and output. ▪︎if your question is related to a code coach exercise,  please mention the tutorial name and the exercise number. thanks!
20th Nov 2021, 7:00 PM
Lothar
Lothar - avatar
+ 1
Missing brain post in Q&A.
20th Nov 2021, 6:31 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Hi, please link your code attempt so we can help you to solve it! Simon Sauter ++🧠;
20th Nov 2021, 7:01 PM
Lisa
Lisa - avatar
+ 1
System.out.println("Missing Number"); Done.
21st Nov 2021, 2:03 AM
A͢J
A͢J - avatar
+ 1
Vijay Maurya Write in same code so we can debug problem.
21st Nov 2021, 2:38 AM
A͢J
A͢J - avatar
+ 1
I have add swap code now you can check
21st Nov 2021, 3:30 AM
Durgvijay Maurya
0
public class MissingNumber { public static void main(String[] args) { int[] arr = {0,2}; sort(arr); System.out.println(Arrays.toString(arr)); } static int sort(int[] arr){ int i=0; while(i < arr.length){ int correct = arr[i] - 1; if(arr[i]< arr.length && arr[i] != arr[correct]){ swap(arr , i ,correct); } else{ i++; } } for (int index = 0; index <arr.length ; index++) { if(arr[index] != index){ return index; } } return arr.length; } static void swap(int arr[] ,int first, int second){ int temp =arr[first]; arr[second] =arr[first]; arr[second] =temp; }}
21st Nov 2021, 2:29 AM
Durgvijay Maurya
0
This is my code
21st Nov 2021, 2:29 AM
Durgvijay Maurya
0
Vijay Maurya Where is swap method in your code and also why you are returning length of arr when you didn't assign to a variable to use that.
21st Nov 2021, 2:34 AM
A͢J
A͢J - avatar
0
Swap method is used from other code
21st Nov 2021, 2:36 AM
Durgvijay Maurya
0
Vijay Maurya You can use Arrays.sort() to sort an array. https://code.sololearn.com/cOTg0k8v5b3S/?ref=app
21st Nov 2021, 7:54 AM
A͢J
A͢J - avatar