ok, I looked it up. here's what the textbook has to say about array initializations:
When an array is created, its elements are assigned the default value of:
0 for the numeric primitive data types,
'\u0000' for char types,
false for boolean types.
Printable View
ok, I looked it up. here's what the textbook has to say about array initializations:
When an array is created, its elements are assigned the default value of:
0 for the numeric primitive data types,
'\u0000' for char types,
false for boolean types.
One more question thats completely unrelated but part of the same assignment.
char1 is a char variable, string is a string variable with a name in it.Code:char1 = (String.charAt[1]).toUpperCase();
This doesn't work, its giving me an error saying that char is not a reference type.
two things about charAt.
1) its a method, so you can't use []. you need ()
2) its non-static, so you can't use "String". but a string object.
For beginner, its best not to chain them because its easy to get confused. The return type for the method charAt() is a char. So what you are trying to do is:
charVar.toUpperCase();
Which is impossible, because...
hint: primary data types.
What would be a good way of capitalizing without any data type confusion?
char1 = (s.toUpperCase()).charAt(1);
well, there are better ways. best to read the java doc.