< (less than)

説明

左側の変数と右側の値または変数を比較します。左側のオペランドが右側のオペランドよりも小さいときに真を返します。異なるデータ型の変数を比較することもできますが、予測できない結果を生む可能性があります。そのため、符号付き/非符号付きを含め同じデータ型の変数を比較することをお勧めします。

構文

x < y; // is true if x is smaller than y and it is false if x is equal or bigger than y

x: 変数。許容されるデータ型:int、float、double、byte、short、long。
y: 変数または定数。許可されたデータタイプ:int、float、double、byte、short、long。

プログラム例

if (x < y) {  // tests if x is less (smaller) than y
  // do something only if the comparison result is true
}

注意点と警告

負の数は正の数よりも小さい。

タイトルとURLをコピーしました