write a program to check whether it is a Lead number or not in java
Answers
Java program to find whether the given number is a lead number or not
A number is said to be a Lead number is the sum of the even digits in the number is equal to the sum of the odd digits in the number.
Program:
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number=sc.nextInt();
int gnumber=number;
int evensum=0;
int oddsum=0;
while(number!=0)
{
int x = number%10;
number = number/10;
if(x%2==0)
{
evensum+=x;
}
else{
oddsum+=x;
}
}
if(evensum==oddsum)
{
System.out.println(gnumber+" is a Lead number");
}
else{
System.out.println(gnumber+" is NOT a Lead number");
}
}
}
Input 1:
6374
Output 1:
6374 is a Lead number
(Explanation:
Odd digits sum = 7+3 = 10 and
Even digits sum = 6+4 = 10.
Therefore, Odd sum=Even sum)
Input 2:
6372
Output 2:
6372 is NOT a Lead number
(Explanation:
Odd digits sum = 7+3 = 10 and
Even digits sum = 6+2 = 8.
Therefore, Odd sum ≠ Even sum)
Learn more:
1. Write a program in Java to generate the following pattern using nested loops.
brainly.in/question/18819254
2. Write a java program to input name and mobile numbers of all employees of any office. Using "Linear Search", search array of phone numbers for a given "mobile number" and print name of employee if found, otherwise print a suitable message.
brainly.in/question/18217872
Explanation:
Imagine that you are a time keeper at the F1 Grand Prix. You keep a record of the time taken by a car to complete a lap in seconds. For easier data keeping, the boss asks you to record the time in minutes and seconds.
[15]
Write a code that takes time in seconds as input. Show the tinle in minutes and seconds
Eg. Input - Time taken: 254 seconds
Output - The time taken is 4 minutes and 14 seconds
please answer thid