Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Isolating Digits using charAt or some other method.

807603Feb 12 2008 — edited Feb 13 2008
When i ask the user to enter a 9 digit sin number ie: "936 564 856" i want my program to A) eliminate spaces to make one big number / integer and B) Apply a algorhithm.

I have got my program to eliminate the spaces by doing this:





String input;
String inputNoSpaces = "";

for( int i = 0; i < input.length(); i++ ){
if ( input.charAt(i) != ' ' ){
inputNoSpaces = inputNoSpaces + input.charAt(i);
}
}



Now i want to apply my algorhithm to every second digits starting from the right so "5,4,5,3" and leave the other ones alone. I was thinking of isolating every second digit using charAt commands or something.

How will i go about doing this - that is isolating every second digit so i can apply my algorhithm.

Edited by: Simplistic2099 on Feb 12, 2008 8:27 AM

Edited by: Simplistic2099 on Feb 12, 2008 8:29 AM

Edited by: Simplistic2099 on Feb 12, 2008 8:29 AM

Edited by: Simplistic2099 on Feb 12, 2008 8:30 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2008
Added on Feb 12 2008
21 comments
386 views