Lead Number in JavaIn 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 NumberIn 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 ExampleLet'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 ProgramUsing FunctionLeadNumberExample1.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 StatementLeadNumberExample2.java Output 1: Enter the number: 27698 27698 is a Lead number. Output 2: Enter the number: 2436876 2436876 is not a Lead number. Next TopicLucky Number in Java |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India