Ok, I’m working on a simple statement code and it works fine as long as the input matches, ie Upper Case. I found it to.UpperCase and it looks simple enough, but still no dice.
my code:
public static void main(String[] args) {
//public static char toUpperCase(char LG) // If I put this in, it gives me 'illegal start of expression'
char LG; // Reads a value of type char.
char UC; // Uppercase value of LG
TextIO.putln("Enter the letter grade do you want converted to point value?");
TextIO.putln();
TextIO.putln("A, B, C, D, or F");
LG = TextIO.getlnChar();
UC = LG.toUpperCase(); //this errors out 'char cannot be dereferenced'
switch ( LG ) {
case 'A':
Thanks for the direction.
The
toUpperCasemethod is one belonging to (at a minimum) theStringorCharacterclasses, you cannot execute it on a primitivechartype. Try:See here for the gory details. Note particularly the shortcomings with respect to full Unicode support. You may be better of using strings instead although you should be okay with that sample code since you only allow
A,B,C,DandF. What happened toEby the way?And, as Ben rightly mentioned in his answer, you should switch on the variable holding the uppercased character rather than the original. In my line above, that’s still
LGsince I see little reason for keeping the original.