Java

Program to add all the digits of a number between 0 and 1000.

Program to add all the digits of a number between 0 and 1000.
import java.util.Scanner;
public class demo1 {

    public static void main(String[] Strings) {

        Scanner input = new Scanner(System.in);

        System.out.print("Input an integer between 0 and 1000:");
        int num = input.nextInt();

        int firstDigit = num % 10;
        int remainder = num / 10;
        int SecondDigit = remainder % 10;
        remainder = remainder / 10;
        int thirdDigit = remainder % 10;

        int sum = thirdDigit + SecondDigit + firstDigit;

        System.out.println("The sum of all digits in " + num + " is " + sum);

    }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.