Dremendo Tag Line

Calculate product and check last digit even or odd in Java

if else - Question 9

In this question, we will see how to input 3 numbers and check if the product of their last digit is even or odd in Java programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q9) Write a program in Java to input 3 numbers and check if the product of their last digit is even or odd.

Program

import java.util.Scanner;

public class Q9
{
    public static void main(String args[])
    {
        int a,b,c,s;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 3 numbers");
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        s=(a%10)*(b%10)*(c%10);
        if(s%2==0)
        {
            System.out.print("Product of their last digit is even");
        }
        else
        {
            System.out.print("Product of their last digit is odd");
        }
    }
}

Output

Enter 3 numbers
18
32
46
Product of their last digit is even
video-poster