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);
}
}
Comments
Post a Comment
Please do not write any spam link in the comment box.