-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighest.java
More file actions
66 lines (65 loc) · 1.06 KB
/
Highest.java
File metadata and controls
66 lines (65 loc) · 1.06 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package practicetime;
import java.util.*;
public class Highest {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println(" Enter the Length of the Array ");
int n=sc.nextInt();
int i,j,count=0,min1=0,min,loc,temp=0;
int a[]=new int[10];
int b[]=new int[10];
System.out.println(" Enter the Elements of the Array ");
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(i=0;i<n;i++)
{
min=a[i];
loc=i;
for(j=i+1;j<n;j++)
{
if(a[j]<min)
{
min=a[j];
loc=j;
}
}
temp=a[i];
a[i]=a[loc];
a[loc]=temp;
}
System.out.println(" Sorted Elements are ----- ");
for(i=0;i<n;i++)
{
System.out.print(" "+a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
count++;
}
}
if((count+1)>=min1)
{
for(int k=0;k<count+1;k++)
{
b[k]=a[i];
}
}
else if(min1>(count+1))
{
min=count+1;
}
}
for(int k=0;k<n;k++)
{
System.out.println(b[k]);
}count =0;
sc.close();
}
}