What will be the output of the following code? -------------------- public static void main(String[] args) { String str = "abbcccddddeeeee"; StringBuilder result = new StringBuilder(); int c = 1; for (int i = 1; i < str.length(); i++) { if (str.charAt(i) == str.charAt(i - 1)) { c++; continue; } result.append(c).append(str.charAt(i)); c = 1; } System.out.println(result); }
Geekific
What will be the output of the following code?
--------------------
public static void main(String[] args) {
String str = "abbcccddddeeeee";
StringBuilder result = new StringBuilder();
int c = 1;
for (int i = 1; i < str.length(); i++) {
if (str.charAt(i) == str.charAt(i - 1)) {
c++; continue;
}
result.append(c).append(str.charAt(i));
c = 1;
}
System.out.println(result);
}
2 weeks ago | [YT] | 3