File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .*;
2+ class Frequency {
3+ public static void main (String args []){
4+ Scanner sc =new Scanner (System .in );
5+ ArrayList <Integer >Digits =new ArrayList <Integer >();
6+ int input []=new int [4 ];
7+ int i , temp , result ;
8+ for (i =0 ;i <4 ;i ++)
9+ input [i ]=sc .nextInt ();
10+ for (i =0 ;i <4 ;i ++){
11+ while (input [i ]>0 ){
12+ Digits .add (input [i ]%10 );
13+ input [i ]=input [i ]/10 ;
14+ }
15+ }
16+ temp =Collections .frequency (Digits ,Digits .get (0 ));
17+ result =Digits .get (0 );
18+ for (i =1 ;i <Digits .size ();i ++){
19+ if (temp <Collections .frequency (Digits ,Digits .get (i ))){
20+ temp =Collections .frequency (Digits ,Digits .get (i ));
21+ result =Digits .get (i );
22+ }
23+ else if (temp ==Collections .frequency (Digits ,Digits .get (i ))&& Digits .get (i )>result ){
24+ temp =Collections .frequency (Digits ,Digits .get (i ));
25+ result =Digits .get (i );
26+ }
27+ }
28+ System .out .println (result );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments