Is the single method printMaxDistance_a or the two methods printMaxDistance_b AND printMaxDistance_c better or respectively "more readable"? Thanks.
public static void printMaxDistance_a(String s) {
int first = 0;
int second = 0;
int max = 0;
for (int i = 0; i < s.length(); i++) {
for (int j = i + 1; j < s.length(); j++) {
if (s.charAt(i) == s.charAt(j)) {
if ((j - i) > max) {
first = i;
second = j;
max = j - i;
}
break;
}
}
}
System.out.println(first + " " + second + " " + max);
}
public static void printMaxDistance_b(String s) {
int first = 0;
int second = 0;
int max = 0;
for (int i = 0; i < s.length(); i++) {
int cur = printMaxDistance_c(s, s.charAt(i), i + 1);
if (cur > max) {
first = i;
second = i + cur;
max = cur;
}
}
System.out.println(first + " " + second + " " + max);
}
public static int printMaxDistance_c(String s, char c, int j) {
for (int i = j; i < s.length(); i++) {
if (c == s.charAt(i)) {
return i - (j - 1);
}
}
return 0;
}
@SuppressWarnings("resource")
public static void main(String[] args) {
String s = new Scanner(System.in).nextLine();
printMaxDistance_a(s);
printMaxDistance_b(s);
}