Java Program to Calculate Sum of Digits

In this tutorial you will learn about the Java Program to Calculate Sum of Digits and its application with practical example.

Java Program to Calculate Sum of Digits

In this tutorial, we will learn to create a Java program that will Print the Sum of digits in a given Number using Java programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:

  • Operators in Java Programming.
  • Basic Input and Output function in Java Programming.
  • Basic Java programming.
  • While loop in Java programming.
  • Conditional Statements in Java programming.
  • Arithmetic operations in Java Programming.

Program to Print Sum of digits in a given Number

In Java programming, we will make a program in today’s tutorial. We will take integer input from the user and find the Sum of digits in a given number with the help of a program. At last, we will print the sum of all the digits in that number.

With the help of this program, we can Print the Sum of digits in a given number.

Algorithm:-

Program to Print Sum of digits in a given number:-

Output:-

In the above program, we have first initialized the required variable.

  • no = it will hold the integer for the input
  • digit = it will hold the digits of the number
  • sum = it will hold the sum of the digits

Input number from the user.

Program Logic Code.

Printing output for sum the digits.

In this tutorial we have learn about the Java Program to Calculate Sum of Digits and its application with practical example. I hope you will like this tutorial.