title: Repitition loops, how to get the sum of the digits of a number
body: <p>guys can u help me answer this exercise using for loop without using string methods, just only integers</p>
  
  <p>Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, the program should output the individual digits of 3456 as 3 4 5 6 and the sum as 18,and output the individual digits of -2345 as 2 3 4 5 and the sum as 14.</p>
  
  <pre><code>import java.util.*;
  
  public class Integer {
      public static void main(String args[]) {
          Scanner console = new Scanner(System.in);
          int input;
          int sum = 0;
          int num1 = 0;
          int counter = 1;
          String num = "";
  
          System.out.print("enter a number: ");
          input = console.nextInt();
  
          if (input == (-input)) {
  
              input = input * (-1);
              num = String.valueOf(input);
              num1 = num.length();
              System.out.print("the digits of " + input + " are: ");
  
              for (int i = 0; i &lt; num1; i++) {
                  String var = num.substring(i, counter);
                  int var1 = Character.getNumericValue(var.charAt(0));
                  System.out.print(var + " ");
                  sum = sum + var1;
                  counter++;
              }
              System.out.println();
              System.out.println("the sum is: " + sum);
  
          } else {
              num = String.valueOf(input);
              num1 = num.length();
              System.out.print("the digits of " + input + " are: ");
  
              for (int i = 0; i &lt; num1; i++) {
                  String var = num.substring(i, counter);
                  int var1 = Character.getNumericValue(var.charAt(0));
                  System.out.print(var + " ");
                  sum = sum + var1;
                  counter++;
              }
              System.err.println();
              System.out.println("the sum is: " + sum);
          }
      }
  }
  </code></pre>