Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- System.out.println(sumOfOddPlace(15624));
- }
- public static int sumOfOddPlace(long number) {
- String num = Long.toString(number);
- int sum = 0;
- boolean odd = true;
- for(int i = num.length(); i > 0; i--) {
- if(odd) {
- int foo = Integer.parseInt(num.substring(i-1, i));
- sum += foo;
- odd = false;
- }
- else
- odd = true;
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement