Write a Java program to find the sum of digits of a given number.

Here’s a Java program to find the sum of digits of a given number:

import java.util.Scanner;

public class SumOfDigits {
    public static void main(String[] args) {
        int num, sum = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        num = scanner.nextInt();
        while (num > 0) {
            int digit = num % 10;
            sum += digit;
            num /= 10;
        }
        System.out.println("Sum of digits: " + sum);
    }
}

In this program, we first take user input for a number. We then use a while loop to iterate over each digit of the number. In each iteration, we use the remainder operator `%` to get the last digit of the number and add it to the `sum` variable. We then divide the number by 10 to remove the last digit. We repeat this process until the number becomes 0.

At the end of the program, we print out the sum of digits of the number.