You cannot cast a String to char. This will give you a compile time error. Why dont you make 'grade1' of type String instead of char. If for some reason you have to cast it from String to char type, than I would suggest using the toCharArray() method in the String class. The method will return you a new character array. Than by using some looping mechanism you can extract the required character and than apply your conditional constraints. Alternately you could also use the charAt(int index) method of the String class to do the conversion, note that the first char value of the sequence is at index zero('0').