Try debugging the code by adding println() statements to print out the values as they are computed so you can see where the code is going wrong.
Type: Posts; User: Norm
Try debugging the code by adding println() statements to print out the values as they are computed so you can see where the code is going wrong.
How is the value 22 computed? Can you show how it is is computed by doing it manually and typing in the values that would be added to the count?
Show it in two or more columns:
the char // the...
What is the problem with the code now?
What does it print out now?
What do you want it to print?
Why multiply by 2 if the String length is divisible by 4 inside of the for loop?
Most of the comments are redundant.
// this tests to see if the symbol at the position of the String at i is...
Please add some comments to the code describing what the statements are trying to do.
For example, what is this statement for:
if( s.length() % 4 == 0){
Don't do it all in one line of code. Break it up into steps
Validate the char
if valid compute the index
use the index
edit: better order (as per Greg)
The index into an array needs to be from 0 to the array's length-1.
The code needs to map the char values it gets into that range, for example: 'a' gives 0 and 'z' gives 25
You can do math with...