6
Write a program to accept a number and check if it is a Mark number or not. A number is said to be Mark when sum of the squares of each digit is an even number as well as the last digit of the sum and the last digit of the number given is same.
Example: n = 246
sum = 2 x 2 + 4 x 4 + 6 x 6 = 56
56 is an even number as well as last digit is 6 for both sum as well as the number.
Show SolutionHide Solution↓
import java.util.Scanner;
class MarkNumber
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n, d, sum = 0, temp;
System.out.print("Enter number: ");
n = sc.nextInt();
temp = n;
while(n > 0)
{
d = n % 10;
sum += d * d;
n = n / 10;
}
if(sum % 2 == 0 && (sum % 10 == temp % 10))
System.out.println("It is a Mark Number");
else
System.out.println("It is not a Mark Number");
}
}
