java - Knowing how many repeat the letters in the String -


i have interview question knowing repeat letters in string solve

string str = "my name java developer";     int count = 0;     (int = 0; < str.length(); i++) {         (int j = 0; j < str.length(); j++) {             if (str.charat(i) == str.charat(j)) {                 count = count + 1;             }          }         system.out.print(count + "  ");         count = 0;     } 

but problem 1 - avoid space count 2-there repeated character counted m in 'my' , m in 'name' don't want repeat count characters 3- want solve in way plus 1

thank ,,

why don't use maps (from character integer)?

hence won't need double for-loops , solves double counting.

but since interview question hesitate give code.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -