There are N numbers, such as 3351353558. Which one is the most?

Source: Internet
Author: User
  1. Import java. util. ArrayList;
  2. Import java. util. Collections;
  3. Import java. util. HashMap;
  4. Import java. util. List;
  5. Import java. util. Map;
  6. /**
  7. * Sorts the occurrences of Characters in the character set.
  8. *
  9. * @ Author Zhao Xueqing www.java2000.net
  10. */
  11. Public class T {
  12. Public static void main (String args []) {
  13. String str = "12345678hfdjkslahfkj932189oiefsjkar94werfdsf ";
  14. Map <Character, KeyValue> map = new HashMap <Character, KeyValue> ();
  15. Char c;
  16. KeyValue kv = null;
  17. For (int I = 0; I <str. length (); I ++ ){
  18. C = str. charAt (I );
  19. Kv = map. get (c );
  20. If (kv = null ){
  21. Kv = new KeyValue ();
  22. Kv. ch = c;
  23. Kv. count = 1;
  24. Map. put (c, kv );
  25. } Else {
  26. Kv. count ++;
  27. }
  28. }
  29. List <KeyValue> list = new ArrayList <KeyValue> (map. values ());
  30. Collections. sort (list );
  31. For (KeyValue o: list ){
  32. System. out. println (o. ch + "=" + o. count );
  33. }
  34. }
  35. }
  36. Class KeyValue implements Comparable {
  37. Public int compareTo (Object obj ){
  38. If (obj instanceof KeyValue ){
  39. KeyValue kv = (KeyValue) obj;
  40. Return kv. count-this. count;
  41. }
  42. Return-1;
  43. }
  44. Char ch;
  45. Int count;
  46. }
  47. Bytes -----------------------------------------------------------------------------------------------------------
  48. Public class TestCount
    {

    /**
    * @ Param args
    */
    Public static void main (String [] args)
    {
    String str = "12455547464515475354635 ";

    Int [] x = new int [10];
    Char [] ca = str. toCharArray ();
    For (int I = 0; I <ca. length; I ++)
    {
    X [ca [I]-'0'] ++;
    }

    For (int I = 0; I <x. length; I ++)
    {
    System. out. println ("character" + (char) ('0' + I) + "appears" + x [I] + "times ");
    }

    }

    }
    Bytes --------------------------------------------------------------------------------------

Public static void main (String [] args ){
Int [] data = {3, 3, 5, 1, 3, 5, 3, 5, 5, 8 };
Map <Integer, Integer> m = new HashMap <Integer, Integer> ();
For (int I = 0; I <data. length; I ++ ){
If (m. get (data [I]) = null ){
M. put (data [I], 1 );
} Else {
M. put (data [I], m. get (data [I]) + 1 );
}
}
System. Out. println ("elements in map:" + M );

Int T = 0;
Set <map. Entry <integer, integer> set = M. entryset ();
For (Entry <integer, integer> entry: Set ){
If (entry. getvalue ()> T ){
T = entry. getvalue ();
}
}

System. Out. println ("the most frequently used :");
For (Entry <Integer, Integer> entry: set ){
If (entry. getValue () = t ){
System. out. println (entry. getKey ());
}
}
}
}---------------------------------------------------------------------------------

Public static void main (String [] args ){
String str = "12455547464515475354635 ";
String out = "";

Char [] ca = str. toCharArray ();

Arrays. Sort (CA );

For (char C: Ca ){
Out + = C;
}

Matcher M = pattern. Compile ("(// d) // 1 *"). matcher (out );

While (M. Find ())
System. Out. println (M. Group (). charat (0) + "count :"
+ M. Group (). Length ());
}----------------------------------------------------------------------

Import javax. Swing .*;

Public class {
Private static String s = JOptionPane. showInputDialog ("Enter a Integer number :");

Public static char getCh (String s ){
Int max = 0;
Char ch = '';

For (int I = 0; I <s. length (); I ++ ){
Char c = s. charAt (I );

Int ntimes = s. length ()-s. replaceAll (Character. toString (c), ""). length ();
If (ntimes> max ){
Max = ntimes;
Ch = c;
}
}

Return ch;
}

Public static void main (String [] args ){
System. out. println ("The number is:" + getCh (s ));
}
}

---------------------------------------------------------------------------

Import javax. Swing .*;

Public class {
Private Static string S = joptionpane. showinputdialog ("enter a integer number :");

Public static char getch (string s ){
Int max = 0;
Char CH = '';

For (INT I = 0; I <S. Length (); I ++ ){
Char c = S. charat (I );

Int ntimes = S. Length ()-S. replaceall (character. tostring (C), ""). Length ();
If (ntimes> MAX ){
Max = ntimes;
Ch = C;
}
}

Return ch;
}

Public static void main (string [] ARGs ){
System. out. println ("The number is:" + getCh (s ));
}
}

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.