if you don`t no how elements are given you will follow this code also ---> public static void main(String[] args) { int a[]= {10,11,13,14,15,16,17}; int sum1=0,sum2=0; for(int i=0;i
@harshadagothankar9652 жыл бұрын
to get correct result of sum2, array needs to be in sorted order
@mayurahire25992 жыл бұрын
@@harshadagothankar965 yes
@msgudaduramath4980 Жыл бұрын
I think here we should know the last element also
@msgudaduramath4980 Жыл бұрын
And I think instead of doing -->i++ in sum2,first we do like int x=a[1]-a[0]; Then in sum2 we can do like -->i+x; It can help when sorted order is like [2,4,6,8]
@msgudaduramath4980 Жыл бұрын
Is it write or wrong bro because I am so confusing here
@TinaLiu-n9u3 ай бұрын
int a[]= {2,3,5,7}; for(int i=0;i
@nileshpardeshi70685 жыл бұрын
How can we calculate if two numbers are missing?
@durgaprasadmajji80572 жыл бұрын
I have also the same dought. Could you possible to write the code for that.
@ninosalkaton44612 жыл бұрын
int arr[] = { 15 ,6 , 7, 10, 11, 13 }; System.out.println("array without sort: "+Arrays.toString(arr)); //sort array ascending Arrays.sort(arr); System.out.println("array with ascending:"+Arrays.toString(arr)); //sort array ascending without Arrays.sort(arr) // int t1; // for(int i=0; i
@fero___30052 жыл бұрын
I think using binary search algorithm
@AmolHiwale1232 жыл бұрын
By using a foreach loop we can compare all the numbers with another list Then we can find n missing numbers
@shreyasgowda6074 Жыл бұрын
let arr = [1, 3, 5]; arr.sort((a,b)=>a-b); let result = []; for(let i=0;i
@mathiyalagan.p42503 жыл бұрын
line 27 for(int i=1;i
@codingamul74682 жыл бұрын
array index start from zero
@teluguoptionbuyers6002 жыл бұрын
yes we can use
@msgudaduramath49802 жыл бұрын
This is possible only when 1st value is 1
@Arshad_Nawaz25267 ай бұрын
Very very simpl explanation ❤
@sdetpavan7 ай бұрын
Thanks
@fedbizdynamicsllc6349 Жыл бұрын
For the missing Element of Array, I have the following code which does not give me the missing number. I think there is something wrong with the condition you stated: public static void main(String[] args) { int arr[]= {1,2,3,4,5,7,8,9}; // steps - sum1 is based on the Index int sum1=0; for (int i=0; i
@ShivamSharma-od3yy Жыл бұрын
For step2 as per your case range will 1 to 9 rather than 5
@AmitYadav-nz5if Жыл бұрын
You've given range till 9 in array but in sum2 for loop, you've given range till 5. So missing number will give you -24
@Rakhiii000 Жыл бұрын
The range is wrong
@Mustaq156 ай бұрын
what if multiple numbers are missing ? in line like (1,4,5,6,7)
@ManmadKumarReddyBhumiReddy Жыл бұрын
Sum of numbers you can do this way .... n*n+1/2
@AmanRaj-kc1uu Жыл бұрын
appreciation for ur efforts that u put in this series
@ruhishabnam88934 жыл бұрын
Sir this program is for 1 missing number..if 2 numbers are missing does it show 2 missing numbers??
@ninosalkaton44612 жыл бұрын
int arr[] = { 15 ,6 , 7, 10, 11, 13 }; System.out.println("array without sort: "+Arrays.toString(arr)); //sort array ascending Arrays.sort(arr); System.out.println("array with ascending:"+Arrays.toString(arr)); //sort array ascending without Arrays.sort(arr) // int t1; // for(int i=0; i
@EasyStuff07 ай бұрын
Sir why so complicated, use int c=arr[0] and compare using for loop for arr[i] with c++ values, if mismatch then missing.. please Let me know on this
@nikhil79472 жыл бұрын
What to do if multiplie numbers are missing
@omkarpatil70572 жыл бұрын
How to find missing num if numbers are not in sequence (we dont knw range values)and array length is very large?
@msgudaduramath4980 Жыл бұрын
To find missing number the array should be in the sorted order and the difference between each element should be same
@lakshmiprasanna7934 Жыл бұрын
The above solution is only for any one value is missing in an array what if multiple values are missing in an array, If any one has the solution for my quiry please respond
@ALdracoyt7 ай бұрын
what if multiple numbers are missing ?
@Mustaq156 ай бұрын
package Array; import java.util.Arrays; public class FindMissingElementInArray { public static void main(String[] args) { int a[]= {1,4,5,6,3}; Arrays.sort(a); int num=a[0]; for(int i=0; i
@softwaretestingbasics53522 жыл бұрын
Really it's veryful...but I have qsn..if suppose if the number in odd or even sequence will it work ?
hello sir if it is depends on user if they type some other numbers. then how can we find the missing numbers? Your logic is only when input is given in the program. please clarify
@ninosalkaton44612 жыл бұрын
int arr[] = { 15 ,6 , 7, 10, 11, 13 }; System.out.println("array without sort: "+Arrays.toString(arr)); //sort array ascending Arrays.sort(arr); System.out.println("array with ascending:"+Arrays.toString(arr)); //sort array ascending without Arrays.sort(arr) // int t1; // for(int i=0; i
@palletimadhu92562 жыл бұрын
I. Have the same doubt?
@archismansural50763 жыл бұрын
This is very hard-coded. A program should be as flexible as possible.
@HarshTV973 жыл бұрын
Its for the interviews of freshers.
@teluguoptionbuyers6002 жыл бұрын
this need to be sorted or use smallest to find the starting number. you made it to start from 1 always.
@valeriyGennadyevich4 күн бұрын
num2 is kinda hardcoded. Here is a method i wrote making num2 dynamic public static int missingNumber(int[]arr){ int num1=0; int num2=0; int maxNum =arr[0]; int minNum = arr[0]; for (int i = 0; i
@deepakdubey14532 жыл бұрын
Thanks Sir ..for this simple approach ..🕺
@sdetpavan2 жыл бұрын
Keep watching
@manikantamutyala2152 Жыл бұрын
super explanation sir
@sdetpavan Жыл бұрын
Thanks
@arvinsuryavanshi6152 жыл бұрын
Sir.If Array series contains multiple missing numbers.this logic works or not
@mdmuddasirulhassan33223 жыл бұрын
if there are more than one missing number.how to find them?
@ninosalkaton44612 жыл бұрын
int arr[] = { 15 ,6 , 7, 10, 11, 13 }; System.out.println("array without sort: "+Arrays.toString(arr)); //sort array ascending Arrays.sort(arr); System.out.println("array with ascending:"+Arrays.toString(arr)); //sort array ascending without Arrays.sort(arr) // int t1; // for(int i=0; i
@Ratan_tata_jii Жыл бұрын
according to your code input: [8,9,11,12,13] output:10 it will come means i will give 5000.
@sdetbyraviteja56810 ай бұрын
Obviously it will come bro but while iteration 2nd for loop we have to give I value as 8 and then in the condition section we have to pass stopping range called 13. So final result we will get 10
@sdetbyraviteja56810 ай бұрын
Give me 5000 thousand bro😂😂😂😂😂 please
@praveenkumar-dr6de2 жыл бұрын
This is only for one missing number in an array. Am I right?
@MrRoy69 Жыл бұрын
Yup
@kvelez Жыл бұрын
package javaapplication23; import java.util.ArrayList; import java.util.Scanner; public class JavaApplication23 { public static void main(String[] args) { int sum = 0, sum2 = 0; int[] a = {1,2,3}; int[] b = {1,2,3,4}; for (int i = 0; i < a.length; i++){ sum += a[i]; } for (int i = 0; i < b.length; i++){ sum2 += b[i]; } System.out.println(Math.abs(sum-sum2)); } }
@swayamprakashbhuyan3 жыл бұрын
Commenting for better reach
@navjotsingh24572 жыл бұрын
ty
@suiiiiii57985 ай бұрын
❤
@UmakantGaidhane Жыл бұрын
We can have below solution as well in more simpler public class FindMissingNumberInArray { public static void main(String[] args) { int arr[] = { 1, 2, 3, 4, 5, 6, 8 }; for (int i = 0; i < arr.length; i++) { for (int j = i + 1; j
@studymaster255 Жыл бұрын
//Secound for loop modified public class MissingNumberFromArray { public static void main(String[] args) { //Array should not have duplicates //Array no need to be sorted order //value should be in range int a[]= {11,12,14,15}; int sum=0; for(int value:a) { sum=sum+value; } System.out.println("Sum of element in array: "+sum); int sum2=0; for(int i=a[0];i
@sivalib3023 Жыл бұрын
it is fine but what will happen if user gives array as a = {15 , 11 , 14 , 12 } as sir said that array can of any order ?
@teluguoptionbuyers6002 жыл бұрын
package FA_Java_Programs; public class ArrayMissingNumber { public static void main(String[] args) { int[] a= {6,3,4,7}; int sum=0; for(int x:a) sum+=x; int start=a[0]; for(int i=0;i
@ninosalkaton44612 жыл бұрын
for missing numbers: int arr[] = { 15 ,6 , 7, 10, 11, 13 }; System.out.println("array without sort: "+Arrays.toString(arr)); //sort array ascending Arrays.sort(arr); System.out.println("array with ascending:"+Arrays.toString(arr)); //sort array ascending without Arrays.sort(arr) // int t1; // for(int i=0; i