-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeatedandmissing.java
More file actions
35 lines (34 loc) · 925 Bytes
/
Copy pathrepeatedandmissing.java
File metadata and controls
35 lines (34 loc) · 925 Bytes
1
2
3
4
5
6
7
8
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
import java.util.Scanner;
import java.util.Arrays;
public class repeatedandmissing {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n,x=1;
System.out.println("enter the number of elements in array : ");
n=s.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
System.out.println("enter the elements : "+i);
ar[i]=s.nextInt();
}
//repeated number
Arrays.sort(ar);
for(int i=0;i<n-1;i++)
{
if(ar[i]==ar[i+1])
{
System.out.println("the epeated number is :"+ar[i]);
}
}
// missing number
for(int i=0;i<n;i++)
{
if(x!=ar[i])
{
System.out.println("the missing number is "+x);
}
x++;
}
}
}