convert input to UpperCase
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 expressio开发者_如何学Pythonn'
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 toUpperCase
method is one belonging to (at a minimum) the String
or Character
classes, you cannot execute it on a primitive char
type. Try:
LG = Character.toUpperCase(LG);
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
, D
and F
. What happened to E
by 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 LG
since I see little reason for keeping the original.
change your switch statement to use UC instead of LG
switch(UC)
精彩评论