LoginSignup
0
0

More than 3 years have passed since last update.

Javaの比較 compareTo()メソッドを使って

Last updated at Posted at 2020-07-06
filename.rb
public static void main(String[] args) {
        System.out.println("-----a.compareTo(b)を使ってみよう!-----");
        //aが大きい場合
        Integer a = 2;
        Integer b = 1;
        System.out.println("a の方が大きい場合" + " " +a.compareTo(b)); // 1 が返る
       //aが小さい場合
        a = 1;
        b = 2;
        System.out.println("a の方が小さい場合" + " " +a.compareTo(b)); // -1 が返る
      //a  b が同じ数字の場合
        a = 1;
        b = 1;
        System.out.println("a と b が同じ場合" + " " +a.compareTo(b)); // 0 が返る


    }

compareTo()・・・・まだ使い道がよくわかりません(笑)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0