import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); long num = input.nextLong(); int sum = 0; while (num != 0) { sum += num % 10; num /= 10; } System.out.println("The sum of the digits is: " + sum); } }