java - Does compareTo work with double type? -
i need make program uses compareto, i'm running issues it.
double sides1 = 1.0; double sides2 = 1.3; int compared = sides1.compareto(sides2);
i run error says
cannot invoke compareto(double) on primitive type double
what doing wrong, , how fix it?
you cannot call methods on primitive values such double
s. can call double.compare
, compare 2 primitive double
s you.
int compared = double.compare(sides1, sides2);
you can compare primitive double
values directly comparison operators ==
, !=
, <
, <=
, >
, >=
.