KnowledgeBoat Logo

Computer Applications

Write a program to input a number. Display the product of the successors of even digits of the number entered by user.
Input: 2745
Output: 15
[Hint: The even digits are: 2 and 4
The product of successor of even digits is: 3*5= 15]

Java

Java Iterative Stmts

ICSE

47 Likes

Answer

import java.util.Scanner;

public class KboatEvenSuccessor
{
    public void computeProduct() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int num = in.nextInt();
        int orgNum = num;
        int prod = 1;
        
        while (num != 0) {
            int digit = num % 10;
            num /= 10;
            
            if (digit % 2 == 0)
                prod = prod * (digit + 1);
        }
        
        if (prod == 1)
            System.out.println("No even digits in " + orgNum);
        else
         System.out.println("Product of even digits successors is " 
         + prod);
    }
}

Output

BlueJ output of Write a program to input a number. Display the product of the successors of even digits of the number entered by user. Input: 2745 Output: 15 [Hint: The even digits are: 2 and 4 The product of successor of even digits is: 3*5= 15]

Answered By

20 Likes


Related Questions