Input 2 decimal numbers and find the floor value of their sum using mathematical functions in Java
Mathematical Functions - Question 4
In this question, we will see how to input 2 decimal numbers and find the floor value of the sum of the numbers in Java programming using the mathematical functions. To know more about mathematical functions click on the mathematical functions lesson.
Q4) Write a program in Java to input 2 decimal numbers and find the floor value of the sum of the numbers.
Program
import java.util.Scanner;
public class Q4
{
public static void main(String args[])
{
float a,b,s;
double x;
Scanner sc=new Scanner(System.in);
System.out.println("Enter 2 decimal numbers");
a=sc.nextFloat();
b=sc.nextFloat();
s=a+b;
x=Math.floor(s);
System.out.println("Floor value of sum = " + x);
}
}
Output
Enter 2 decimal numbers 12.36 8.47 Floor value of sum = 20.0