Iterate through a number starting at the end and adding every other digit
This is my first post, and I'd consider my knowledge of Java to be virtually nonexistent. I know a little, but I'm having some trouble with the logic and the syntax of an exercise.
Hopefully, I explained the gist of the problem in the subject, but I will try to rephrase it in case it was unclear.
Ok, so let's say I have a string.
Scanner in = new Scanner(System.in);
String str = "12345678"; // I want to read the string as an int
in.next( ); // I think that converts the string into an int, is that correct?; is it in.next(), or in.nextInt(), or maybe even in.nextLine()
// That's part 1 - if I use the Scanner class what method will convert a String to an int?
Now, I want to go to the end of the String/int "12345678", starting at the end of the, I'll call it, an int, and starting with the last digit, count backwards, skip every other digit and finally add all of the digits together.
In other words, I want to take String str = "12345678"; convert that to the integer 12345678, go to the end of the line, and iterate backwards through the line starting at 8. It would be 8642, but I want to add them, so it would be 8 + 6 + 4 + 2.
Thanks; I'm sorry if I rambled on there, I just wanted to be sure I was clear.
Any help would be appreciated!
Have a good one!