Java Program to print sum of the square of each given digit

 Java Program to print sum of the square of given digit

 A program that accepts a positive number as input and calculates the sum of squares of individual digits of the given number.

Java Program to print  sum of the square of given number by Do WHILE Loop

Example

Input and Output Format:

Input consists of an integer.
Enter the number :
23
2*2+3*3

Output consists of an integer.
Sum of square of Digits is : 13


import java.util.Scanner;

class SumofSqDigits
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number:");
int n = sc.nextInt();
int sum = 0;
do{
int a = n%10;
sum = sum+a*a;
n = n/10;
      }while(n!=0);
System.out.println("Sum of square of Digits is: "+sum);
}
}

Sample Input:

Enter the number:
32

Sample Output:

Sum of square of Digits is:
13



Comments

Popular posts from this blog

Java Program for shop Bill to Calculate total amount of product with discount

RCM|Consequences of imbalanced Nutrition|WHO share daily need

Start your day with healthy PVMF breakfast|Nutricharge prodiet