Scanner sc = new Scanner(System.in); int i = sc.nextInt(); int sum = 0; while (i != 0) { sum += i % 10; i = i / 10; } System.out.println(sum);