title: How do I find the sum of all odd digits of user input numeric string?
body: <p>I need to find the sum of all odd digits of user input numeric string. For example, if the input is 12235, the sum would be 1 + 3 + 5 = 9.</p>
  
  <p>This is what my code looks like so far:</p>
  
  <pre><code> import javax.swing.JOptionPane;
   public class sumOfAllOddDigits
   {
      public static void main( String[]args )
      {
        int a;
        int sum = 0;
        String userinput; 
  
        userinput = JOptionPane.showInputDialog( "Enter a number. " , null);
  
        a = Integer.parseInt(userinput);
  
        for (int i = 0; i &lt;= a; i++)
        {
            if (i % 2 == 1)
            {
                sum += i;
  
            }
  
        }
        System.out.println( sum );
     }
  }
  </code></pre>
  
  <p>The sum always prints a large number, but I do not know how to make it print the correct number. Please help. Thanks. </p>