Question 9
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
String raw = " Learn JAVA Online ";
String slug = raw.strip().toLowerCase().replace(' ', '-');
System.out.println(slug + " " + slug.length() + " " + slug.startsWith("learn") + " " + slug.contains("java-o"));
}
}
- A learn-java-online 17 true true Correct
- B learn-java-online 21 true true
- C --learn-java-online-- 21 false true
- D learn-java-online 17 true false
Correct Answer: Option A
strip removes the outer spaces first, so only the two inner spaces become hyphens.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!