hello! I am trying to create a program that will take 8-digits, flip it around, and read them backwards. So far, I have:
[code]for (i = 7; i < length; i-=2)
System.out.print (creditCardNumber.substring(i, i+1));
System.out.print (new StringBuilder(creditCardNumber).reverse().toString());
I get an error message that says: "[italic]String index out of range: -1[/italic]." how do i stop it after it gets out of range?
Also, I would like to set the reversed, backwards string to a variable, but I know I can't do it in the for statement because it will print out the variable every time. I couldn't really do it outside since the for statement won't be there. Would an if statement do it?