I am a newcomer trying to learn java. I am doing a project for my class in which we are creating a hexadecimal-decimal converter. I already have the conversion finished, but when I print out the hexadecimal result, the letters (because hexadecimal contains A-F) print out in lowercase. I tried the following code to read through the character array and capitalize any lowercase characters:
int i = Integer.parseInt(input);
String hex = Integer.toHexString(i);
char[] hexchar = hex.toCharArray();
for(int j=0; j<=hexchar.length; j++){
if(hexchar[j].equals("a")){
hexchar[j]=hexchar[j].toUpperCase();
}
}
I was going to set up this code for the letters a-f, but the error I keep getting is that a Char array can’t be deferred. Does anyone know if there is a way to read through the char array or can submit a possible workaround?
You can’t apply
toUpperCaseto a char, which is a primitive: it is a method of the String class. The following code should do what you want: