[Java] Java comparison using compareTo() method

less than 1 minute read

filename.rb


public static void main(String[] args) {
         System.out.println("Let's use -----a.compareTo(b)!-----");
// If a is large
Integer a = 2;
Integer b = 1;
System.out.println("a is larger" + "" +a.compareTo(b)); // returns 1
        // if a is small
a = 1;
b = 2;
System.out.println("a is smaller" + "" +a.compareTo(b)); // returns -1
       //a and b are the same number
a = 1;
b = 1;
System.out.println("a and b are the same" + "" +a.compareTo(b)); // returns 0
It's a sequel.
It's a sequel.
}

compareTo()・・・・I still don’t know how to use it (laughs)