title: How to find the product and sum of digits of a number in java?
body: <p>I need to find the sum and the product of the digits of the number entered. I have the sum part down but the only problem with it is that when I enter a number for the first time it gives me the right answer but when I enter another number, it just adds the sum of the first number and the sum of the second number together and then checks if the sum of the two sums is odd(sorry if its kind of confusing). For the product part of the code I just can't seem to figure out how to do it.</p>
  
  <p>Finally if the sum and the product both are odd I need it to say that the number entered is an Extremely odd number. </p>
  
  <p>Here is the assignment:</p>
  
  <p>This Java application checks whole numbers in the interval [101, 100001] to see if they are "extremely odd" and "super extremely odd" numbers.</p>
  
  <p>A whole number is "extremely odd" if...</p>
  
  <p>(0) it's an odd number
   (1) it has an odd number of digits
   (2) all of its digits are odd numbers
   (3) the sum of its digits is an odd number
   (4) the product of its digits is an odd number</p>
  
  <p>A "super extremely odd" number is an extremely odd number such that...</p>
  
  <p>(5) all digits comprising the sum of its digits are odd numbers
   (6) all digits comprising the product of its digits are odd numbers</p>
  
  <p>Loop prompting the user to enter positive whole numbers. Looping ends when a -1 is entered. For each number entered, check to see if its extremely odd (or super extremely odd).</p>
  
  <p>If somebody could just explain what the requirements for the super extremely odd numbers part are saying that would be appreciated because English is not my first language.
  I don't need anyone to do the whole assignment. I just need help on the parts that I'm stuck in. Thank you in advance!</p>
  
  <pre><code>public class TestOddNumbers {
  
    public static void main(String[] args) {
  
      Scanner stdin = new Scanner(System.in);
      int userInput;
      int sum = 0;
      int product = 1;
      final int EXIT = -1;
      final int MIN = 101;
      final int MAX = 100001;
      String total = "";
  
      do{
          System.out.println("Please enter a positive whole number between "
                  + "" + MIN + " and " + MAX + ". Enter " + EXIT + " "
                  + "when you are done entering numbers.");
  
          userInput = stdin.nextInt();
          total += String.valueOf(userInput);
  
          if(userInput==EXIT){
          System.out.println("Thanks for playing!");
          break;
          }
  
          if(userInput &gt; MIN &amp;&amp; userInput &lt; MAX){
              if(userInput % 2 == 1){
              System.out.println("It's an odd number");
              }
              else{
                  System.out.println("Not an odd number");
              }
  
              if(total.length() %2 == 1){
              System.out.println("It also has an odd number of digits");
              }
              else{
              System.out.println("Does not have an odd number of digits");
              }
  
              boolean[] allOdds = {true};
  
              String.valueOf(userInput).chars().forEach(i -&gt; {
              if(Integer.parseInt(String.valueOf((char)i))%2==0){
              allOdds[0] = false;
              }
              });
  
              if(allOdds[0]){
                  System.out.println("all digits are odds");
              }
              else{
                  System.out.println("all digits are not odds");
              }
  
              // The sum code block
              while (userInput != 0) {
                  sum += userInput % 10;
                  userInput /= 10;
              }
              if((sum += userInput) % 2 == 1){
                  System.out.println("The sum of the digits are odd");
              }
              else{
                  System.out.println("The sum of the digits are not odd");
              }
  
              // The product code block
              while(userInput != 0) {
                  product *= userInput % 10;
                  userInput /= 10;
              }
              if((sum *= userInput) % 2 == 1){
                  System.out.println("The product of the digits are odd");
              }
              else{
                  System.out.println("The product of the digits are not odd");
              }
  
          }
          else{
              System.out.println("Check the bounds again!!");
          }
  
          System.out.println();
      } 
      while(userInput &gt; MIN || userInput &lt; MAX);
  
     }
  }
  </code></pre>