I am comparing 2 double values which I receive from user input.
Here is the code:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter two numbers: ");
Double a = scan.nextDouble();
Double b = scan.nextDouble();
if (a>b){
System.out.println("Largest is: " + a);}
if(b>a){
System.out.println("Largest is: " + b);}
System.out.println(a+""+b);
if (a==b){
System.out.println("Largest is: " + b);}
}
}
This code works when I input double values that are greater than/ less than each other. However, this code does not work when I input two of the exact same double values(for example: 9.0
and 9.0
)
Why is this?
Thanks in advance