Dremendo Tag Line

Input 2 decimal numbers and check ceil value of the remainder is even or odd using mathematical functions in Java

Mathematical Functions - Question 5

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

Q5) Write a program in Java to input two decimal numbers and check if the ceil value of their remainder is even or odd.

Program

import java.util.Scanner;

public class Q5
{
    public static void main(String args[])
    {
        float a,b,r;
        double x;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 2 decimal numbers");
        a=sc.nextFloat();
        b=sc.nextFloat();
        r=a%b;
        x=Math.ceil(r);
        if(x%2==0)
        {
            System.out.println("Even Number");
        }
        else
        {
            System.out.println("Odd Number");
        }

    }
}

Output

Enter 2 decimal numbers
11.31
7.24
Odd Number
video-poster