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.
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 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.
Steps to Check Lead Number
Let's implement the above logic in a Java example.
Lead Number Java Program
Enter a number: 29041 It's a Lead number.
Enter a number: 1372 It's not a Lead number.
Let's see another logic for the same.
Using if-else Statement
Enter the number: 27698 27698 is a Lead number.
Enter the number: 2436876 2436876 is not a Lead number.