Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
for statement errors and troubels
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?