Preview:
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.println("Enter Your Number");
    int n = in.nextInt();
    int sum = 0;
    while(n>0){
      int lastdig = n%10;
       sum = sum+lastdig;
       n = n/10;
    }
    System.out.println(sum);
  } 
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter