Dremendo Tag Line

Input a decimal number and check ceil value is even or not using mathematical functions in Java

Mathematical Functions - Question 3

In this question, we will see how to input a decimal number and check if the ceil value of the number is even or not in Java programming using the mathematical functions. To know more about mathematical functions click on the mathematical functions lesson.

Q3) Write a program in Java to input a decimal number and check if the ceil value of the number is even or not.

Program

import java.util.Scanner;

public class Q3
{
    public static void main(String args[])
    {
        float a;
        double x;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a decimal number ");
        a=sc.nextFloat();
        x=Math.ceil(a);
        if(x%2==0)
        {
            System.out.print("Even Number");
        }
        else
        {
            System.out.print("Not Even Number");
        }
    }
}

Output

Enter a decimal number 12.3
Not Even Number
video-poster