Write a program to input 3 numbers. calculate and print their
product. find out whether the product is an even or an odd number.
print with appropriate messages.
Answers
import java.util.Scanner; // importing java.util package to accept the three nunbers from the user
public class Program // title of the program, every java program must have a title
{
// the main function
public static void main(String[] args) {
// creating object of scanner
Scanner sc = new Scanner(System.in);
// taking user input to accept the first number and storing it in double data type. since we don't what data type the user will input
System.out.print("Enter the first nunber: ");
double a = sc.nextDouble();
// again taking user input to accept the second nunber from the user and storing it in doubtle daya type
System.out.print("Enter the second nunber: ");
double b = sc.nextDouble();
// again taking user input to accept the third nunber from the user and storing it in doubtle daya type
System.out.print("Enter the third nunber: ");
double c = sc.nextDouble();
// now multiplying all the accepted numbers using * operator
double product = a * b * c;
// printing the result of "product" using println() function
System.out.println("The product if three nunbers is: " + product);
// now as mentioned in the question, we also have to check the product is even or odd
// so we have to use if and else statement to do so
// checking the product is even or odd
if (product % 2 == 0)
{
System.out.println("The product is an even number.");
}
else
{
System.out.println("The product is an odd number.");
}
}
}