Lead Number in Java

In this section, we will learn what is a lead number and also create Java programs to check if the given number is a lead number or not. The lead number program frequently asked in Java coding tests and academics.

Lead Number

In a given number if the sum of even digits is equal to the sum of odd digits such numbers are called lead numbers.


Lead Number in Java

Lead Number Example

Let's take the number 1452 and check it is a lead number or not.

Even digits are: 4, 2

The sum of even digits = 4 + 2 =6

Odd digits are: 1, 5

The sum of odd digits = 1 + 5 =6

We observe that the sum of even digits is equal to the sum of odd digits. Hence, the given number 1452 is a lead number.

Similarly, we can check other numbers also.

NumberEven DigitsSum of Even DigitsOdd DigitsSum of Odd DigitsComparing SumLead or Not
15687236, 8, 2161, 5, 3, 71616=16Lead
67326, 287, 3108≠10Not Lead
1372221, 3, 7112≠11Not Lead
290412, 4, 069, 1106≠10Not Lead
63696, 6123, 91212≠12Lead

Steps to Check Lead Number

  1. Read or initialize an integer N.
  2. Find the last digit (x) of the number N by using the modulo (%) operator.
  3. Divide the number by 10. It removes the last digit.
  4. Check if the digit (x) is even or odd.
    • If the digit is even added it to a variable evenSum.
    • If the digit is odd added it to a variable oddSum.
  5. Compare the even and odd sum.
    • If the sum is equal, the number N is a lead number.
    • If the sum is not equal, the number N is not a lead number.

Let's implement the above logic in a Java example.

Lead Number Java Program

Using Function

LeadNumberExample1.java

Output 1:

Enter a number: 29041
It's a Lead number.

Output 2:

Enter a number: 1372
It's not a Lead number.

Let's see another logic for the same.

Using if-else Statement

LeadNumberExample2.java

Output 1:

Enter the number: 27698
27698 is a Lead number.

Output 2:

Enter the number: 2436876
2436876 is not a Lead number.