-3

I'm looking for a way to sum up the numbers located in specific positions like say the even positions. So if the user enters 84920 0 is in position 1, 2 is in position 2, 9 is in position 3 so on and so forth. The sum of the numbers in even positions would be 2+4=6. So far all I have is this:

 import java.util.Scanner; 

 public class Sums { 

 public static void main (String[] args){      

 Scanner myScanner; 
 myScanner = new Scanner(System.in); 
 System.out.println("Enter a number: "); 
 int A = myScanner.nextInt(); 
jenncar
  • 5
  • 1
  • 3
  • 2
    You don't have nothing about the algorithm you have to implement – nachokk Sep 21 '13 at 22:14
  • 1
    Check out http://stackoverflow.com/questions/3389264/how-to-get-the-separate-digits-of-an-int-number for help on getting the digits out. – arynaq Sep 21 '13 at 22:15

1 Answers1

-1
import java.util.Scanner;
class Sums {
    public static void main(String[] args){
        Scanner myScanner = new Scanner(System.in);
        int sum = 0;

        do{
            System.out.print("enter number: ");
            int x=myScanner.nextInt(); 
            sum +=x; 
        } while(sum < 84920);
        System.out.println("total is: "+sum); 
    }
}
Meredith
  • 3,928
  • 4
  • 33
  • 58