I am trying to write a program that randomly generates a number up to five digits and then prints the sum of the digits. I know how to generate the number and I think I am removing the first number correctly, but I get lost after that. Here's what I have tried. I know that my output isn't correct but I have it set up like this so that I can see if I am pulling the numbers out correctly. Once I have that figured out I'll change the output to sum the individual digits.

Code:

public class ProgrammingProblemOne {

public static void main(String[] args) {

//generate random number

int n = (int)Math.floor(Math.random()*100000+1);

//pull out first digit

int tenThousands = n / 10000;

//pull out second digit

int thousands = n / 1000;

/pull out third digit

int hundreds = n / 100;

//pull out fourth digit

int tens = n / 10;

//pull out fifth digit

int ones = tens / 1;

System.out.println("Generated number: " + n);

System.out.println("First digit: " + tenThousands);

System.out.println("Second digit: " + thousands);

System.out.println("Third digit : " + hundreds);

System.out.println("Fouth digit: " + tens);

System.out.println("Fifth digit: " + ones);

}

}