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
Post a Comment