import java.util.Scanner; public class A { public static void main(String[] args){ Scanner input = new Scanner(System.in); int sum; System.out.println("Enter a number between 0 and 1000: " ); int num = input.nextInt(); if(num <= 99){ int num1 = num % 10; int num2 = num / 10; sum = num1 + num2; } else { int num1 = num % 10; int num2 = num % 100 / 10; int num3 = num / 100; sum = num1 + num2 + num3; } System.out.println("The sum of the digits is " + sum); } }