| 1. |
Write a program to check whether it is a Lead number or not in java |
Answer» Java program to find whether the given number is a lead number or notA 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: 6374Output 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: 6372Output 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. 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. |
|