- 1
why string!! in spite of char?
In this code we are using single letters, so we should use char but why did thay use string? public class Program { public static void main(String[] args) { String[ ] myNames = { "A", "B", "C", "D"}; System.out.println(myNames[2]); } }
2 Answers
+ 11
a string can be a single character as well
furthermore, if you were to use
char[ ] myNames = .....
you would have needed to declare the array elements with a single quatation marks:
char[ ] myNames = {'A', 'B', 'C', 'D'};
and for next time, please make an actual code and post it instead of just pasting it here....
it would allow others to help you more easily
+ 3
Maybe they shouldn't, maybe they want multiple characters sometimes.
Who knows without the actual code.