lec 4 Flashcards

(30 cards)

1
Q

What is the Java data type used for true/false values?

A

boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the possible values of a boolean type?

A

true and false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an example of declaring a boolean variable?

A

boolean isJavaFun = true;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can a boolean store values other than true or false?

A

No, it can only hold true or false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you print a boolean value in Java?

A

System.out.println(isJavaFun);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the output of System.out.println(5 > 3);?

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the output of System.out.println(10 == 15);?

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the result of boolean b = (1 > 2);

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a boolean expression in Java?

A

An expression that returns true or false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What operator is used to check if two values are equal?

A

==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What operator checks if a value is not equal?

A

!=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What will System.out.println(10 >= 9); output?

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are relational operators used for?

A

To compare values and return a boolean result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the Java equivalent of the mathematical symbol ≤?

A

<=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does > check for?

A

If one value is greater than another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does System.out.println(10 < 5); output?

17
Q

How does != behave?

A

Returns true if values are not equal, otherwise false.

18
Q

What will System.out.println(100 == 100); output?

19
Q

What does System.out.println(5 == 5); return?

20
Q

How would you check if x is greater than y in Java?

21
Q

What is the output of System.out.println(8 <= 8);?

22
Q

What is the output of System.out.println(3 != 3);?

23
Q

How are boolean expressions commonly used?

A

In conditions for if statements and loops.

24
Q

How do you check if a variable age is at least 18?

25
What happens when you compare true == false?
It evaluates to false.
26
What does System.out.println(0 == false); return?
Compilation error (boolean is not directly comparable to integers).
27
How do you use a boolean in an if statement?
if (isJavaFun) { System.out.println("Java is fun!"); }
28
What will System.out.println(!true); output?
false
29
What does ! do in a boolean expression?
It negates the boolean value (true becomes false, and vice versa).
30
What will System.out.println(!(10 > 5)); output?
false