I have a homework assignment that I'm having difficulties with. I read that it is a no-no to ask for someone to do the homework and I'm not looking for that. A little nudge in the right direction is what I'm looking for. Anyway, my problem is to take a variable, get it's first initial and the ASCII equivelant to print on the same line. Here is what I have so far: (for troubleshooting purposes, you should know that the variables already have values.)
char firstInitial = (first.charAt(0)); //This sets the value for the initial using the first name char lastInitial = (last.charAt(0)); //This sets the value for the initial using the last name System.out.println((char)firstInitial + '\t' + " " + ((int)firstInitial) ); //Trying to force the first part into a character System.out.println((char)lastInitial + '\t' + " " + ((int) lastInitial) ); //Keep getting both variables as integers
When my code runs I get two ASCII values per line. The second ASCII value on the line is correct for my initial, the first ASCII value is nine values higher (ex. 109 100).
I asked my professor and he said I do not need the variables firstInitial and lastInitial. I should be able to get the value in the print statements. He said I also had too many parentheses around the ascii conversion of the first and last name initials...
So I modified my code to:
System.out.println("Inits ASCII Value");
System.out.println(first.charAt(0) + (int)first.charAt(0) ); //Trying to force the first part into a character
System.out.println(last.charAt(0) + (int)last.charAt(0) ); //Keep getting both variables as integers
Now my code is converting both variables to integers and adding the values. Any thoughts?

New Topic/Question
Reply




MultiQuote




|