In: Computer Science
Meant to be written in Java JDK 14.0
1. Define 2 double variables. (a) Use method(s) define in Math class to check if these 2 numbers are equal or not. Display result (b) Write code (not to use Math method) check if these 2 numbers are equal or not. Display result
Java Program:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter First Double Number : ");
double x = sc.nextDouble();
System.out.print("Enter Second Double Number : ");
double y = sc.nextDouble();
// (a.) Using Math class
if (Math.abs(x) == Math.abs(y))
{
System.out.println("\nBoth Numbers are equal using Math class");
}
else
{
System.out.println("\nBoth Numbers are not equal using Math class");
}
// (b.) Without using Math class
if (x == y)
{
System.out.println("\nBoth Numbers are equal !!");
}
else
{
System.out.println("\nBoth Numbers are not equal !!");
}
}
}
Output:
Thumbs Up Please !!!