public class MissingNumberInArray {
public static void main(String args[]){
int a[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
int asum = 0,sum = 0;
for(int i=1;i<=a.length;i++)
sum=sum+i;
for(int i=0;i<a.length;i++)
asum=asum+a[i];
int missnum=sum-asum;
System.out.println("Missing Number"+missnum);
}
}
Output:-
Missing Number =>20
0 comments :