Thursday, 15 May 2014

java - Check if all chars match? -



java - Check if all chars match? -

basically, have write method determines whether characters in string same, using library string methods.

public static void main(string[] args) { string str = "aaaaa"; int count = str.length() - str.replaceall(string.valueof(str.charat(0)), "").length(); if(count == str.length()) system.out.println("all characters in given string same"); }

try : simplest , best solution kind of problem.

java

No comments:

Post a Comment