Question 20
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
char[] word = {'J', 'a', 'v', 'a'};
System.out.println(word); // println(char[]) prints the characters
System.out.println(String.valueOf(word, 1, 2));
System.out.println(word.length + word[0]); // int + char: arithmetic
}
}
- A Java av 78 Correct
- B [J, a, v, a] av 78
- C Java va 4J
- D Java av 4J
Correct Answer: Option A
println has a special overload for char[] that prints the characters. 4 + 'J' (74) is the int 78.
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!