lec 4 Flashcards
(30 cards)
What is the Java data type used for true/false values?
boolean
What are the possible values of a boolean type?
true and false
What is an example of declaring a boolean variable?
boolean isJavaFun = true;
Can a boolean store values other than true or false?
No, it can only hold true or false.
How do you print a boolean value in Java?
System.out.println(isJavaFun);
What is the output of System.out.println(5 > 3);?
true
What is the output of System.out.println(10 == 15);?
false
What is the result of boolean b = (1 > 2);
false
What is a boolean expression in Java?
An expression that returns true or false.
What operator is used to check if two values are equal?
==
What operator checks if a value is not equal?
!=
What will System.out.println(10 >= 9); output?
true
What are relational operators used for?
To compare values and return a boolean result.
What is the Java equivalent of the mathematical symbol ≤?
<=
What does > check for?
If one value is greater than another.
What does System.out.println(10 < 5); output?
false
How does != behave?
Returns true if values are not equal, otherwise false.
What will System.out.println(100 == 100); output?
true
What does System.out.println(5 == 5); return?
true
How would you check if x is greater than y in Java?
x > y
What is the output of System.out.println(8 <= 8);?
true
What is the output of System.out.println(3 != 3);?
false
How are boolean expressions commonly used?
In conditions for if statements and loops.
How do you check if a variable age is at least 18?
age >= 18