In this section, you will learn how you can easily check the lead number by using Java program.
What is Lead Number?
It is a number in which the sum of even digits is equal to the sum of the odd digits or vice-versa, Let's see:
For example : 6325
Sum of even number : 6 + 2 = 8
Sum of add number : 3 + 5 = 8
Here, the Sum of even number is equal to the sum of the odd digits, So 6325 is a lead number.
Let's try to create a simple program :
➤ Code : LeadNumber.java;
import java.util.*;
class LeadNumber{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
System.out.print("Enter a number to check the number is Lead Number : ");
int number = input.nextInt(); // 6325
int r=0,odd=0,even=0;
while(number>0)
{
r=number%10; //5,2,3,6
if(r%2==0){
even=even+r; //2+6 = 8
}
else{
odd=odd+r; // 3 + 5 = 8
}
number = number/10;
}
if(odd==even)
System.out.println("This is a Lead Number");
else
System.out.println("This is not a Lead Number");
}
}
Output :
Enter a number to check the number is Lead Number : 6325
This is a Lead Number
Comments