What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
String sentence = "Java is fun";
String[] words = sentence.split("\\s+");
StringBuilder sb = new StringBuilder();
for (int i = words.length - 1; i >= 0; i--) {
sb.append(words[i]);
if (i > 0) sb.append(' ');
}
System.out.println(sb + "|" + new StringBuilder(sentence).reverse());
}
}
Splitting on \s+ collapses the double spaces; reversing the whole builder reverses every character, spaces included.