LoginSignup
1
0

More than 1 year has passed since last update.

Java 基本の基本4

Last updated at Posted at 2022-12-02

はじめに

自身でprogataやスクールでJavaを勉強中。学んだことをアウトプットして、より定着させるために記事にまとめていきます。継続は力なり!

演算子(前回の続き)

関係演算子

int num1 = 10;
int num2 = 5;
boolean result;

result = (num1 == num2) //false
result = (num1 != num2) //true
result = (num1 > num2) //true
result = (num1 <= num2) //false

論理演算子

int num1 = 10;
int num2 = 5;
boolean result;
//and
result = ((num1 < 10) && (num2 < 10)) //false
//or
result = ((num1 < 10) || (num2 < 10)) //true
//notand
result = !(num1 < num2) //true

文字列の比較

文字列は参照型データなので、==は使えません。

String str1 = "山田";
String str2 = "やまだ";
String str3 = "山田";
boolean result;

result = str1.equals(str2); //false
result = str1.equals(str3); //true
result = str1.equals("山田"); //true
1
0
0

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
1
0