Java Tutorial/Operators/Relational Operators

Материал из Java эксперт
Версия от 17:44, 31 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Relational and logical operators

import java.util.Random;
public class MainClass {
  public static void main(String[] args) {
    Random rand = new Random();
    int i = rand.nextInt(100);
    int j = rand.nextInt(100);
    System.out.println("i = " + i);
    System.out.println("j = " + j);
    System.out.println("i > j is " + (i > j));
    System.out.println("i < j is " + (i < j));
    System.out.println("i >= j is " + (i >= j));
    System.out.println("i <= j is " + (i <= j));
    System.out.println("i == j is " + (i == j));
    System.out.println("i != j is " + (i != j));
    System.out.println("(i < 10) && (j < 10) is " + ((i < 10) && (j < 10)));
    System.out.println("(i < 10) || (j < 10) is " + ((i < 10) || (j < 10)));
  }
}



i = 92
j = 22
i > j is true
i < j is false
i >= j is true
i <= j is false
i == j is false
i != j is true
(i < 10) && (j < 10) is false
(i < 10) || (j < 10) is false


Relational Operators

Relational OperatorsDescription>greater than>=greater than or equal to==equal to!=not equal to<=less than or equal to<less than