java☹️

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/51

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

52 Terms

1
New cards

What are boolean variables used for in programming?

To compare two values and represent the result as true or false.

2
New cards

What is the purpose of relational operators in Java?

To compare two values and return a boolean result.

3
New cards

List the six relational operators in Java.

4
New cards

What does the operator '==' signify?

It checks if two values are equal.

5
New cards

What is the syntax for a one-way if statement?

if (boolean-expression) { statement(s); }

6
New cards

Provide an example of a one-way if statement.

if (radius >= 0) { area = radius * radius * PI; }

7
New cards

What is the structure of a two-way if statement?

if (boolean-expression) { statement(s)-for-true-case; } else { statement(s)-for-false-case; }

8
New cards

How does a multi-way if-else statement operate?

It checks multiple conditions in sequence until one is true.

9
New cards

What is a common mistake when using if statements?

Adding a semicolon at the end of an if clause.

10
New cards

What is the purpose of logical operators?

To combine multiple boolean expressions.

11
New cards

List the logical operators in Java.

! (not), && (and), || (or), ^ (exclusive or)

12
New cards

What does the '&&' operator represent?

Logical conjunction; it returns true if both operands are true.

13
New cards

What does the '||' operator represent?

Logical disjunction; it returns true if at least one operand is true.

14
New cards

What is the purpose of the switch statement?

To execute different parts of code based on the value of a variable.

15
New cards

What is a common technique to debug errors in if statements?

Trace through the conditions and check the flow of execution.

16
New cards

What is the conditional expression syntax in Java?

condition ? expressionIfTrue : expressionIfFalse

17
New cards

What is the result of the expression '!(age > 18)' if age is 24?

false, because (age > 18) is true.

18
New cards

What happens if the condition in an if statement is false?

The statements inside the if block are skipped.

19
New cards

How can you compute taxes based on filing status in Java?

Using a series of if-else statements to check the filing status.

20
New cards

What is the result of 'radius < 0' if radius is 5?

false

21
New cards

What does the operator '!=' signify?

It checks if two values are not equal.

22
New cards

What is the output of the following code if score is 70.0? if (score >= 70.0) System.out.print('C');

'C'

23
New cards

What is the significance of operator precedence?

It determines the order in which operations are performed in expressions.

24
New cards

What is the output of 'System.out.print("A");' if score is 95.0?

'A', because the condition score >= 90.0 is true.

25
New cards

What does the 'else' clause match in an if-else statement?

The most recent if clause in the same block.

26
New cards

What is the output of 'System.out.println("Negative input");' if radius is -1?

'Negative input'

27
New cards

What does the operator '||' represent?

'||' represents the logical OR operator.

28
New cards

What is the result of (age > 34) || (weight <= 140) when age is 24 and weight is 140?

True, because (age > 34) is false and (weight <= 140) is true.

29
New cards

What does the operator '^' represent?

'^' represents the logical XOR (exclusive OR) operator.

30
New cards

What is the result of (age > 14) ^ (weight > 140) when age is 24 and weight is 140?

True, because (age > 14) is true and (weight > 140) is false.

31
New cards

What does the '&&' operator do?

'&&' represents the logical AND operator.

32
New cards

What is the output of the expression (number % 2 == 0) && (number % 3 == 0)?

It checks if the number is divisible by both 2 and 3.

33
New cards

What data types can the switch expression yield?

char, byte, short, or int.

34
New cards

What happens if a break statement is omitted in a switch case?

The next case statement will be executed (fall-through behavior).

35
New cards

What is the syntax for a switch statement?

switch (expression) { case value1: statements; break; … default: statements; }

36
New cards

What is a conditional expression in Java?

An expression that evaluates to one of two values based on a boolean condition, using the ternary operator.

37
New cards

How is the ternary operator structured?

boolean-expression ? expression1 : expression2.

38
New cards

What is operator precedence?

The rules that determine the order in which operators are evaluated in an expression.

39
New cards

What is the order of operations for the following operators: *, /, +, -?

Multiplication and division are evaluated before addition and subtraction.

40
New cards

What is the associativity of binary operators?

Most binary operators are left-associative, meaning they are evaluated from left to right.

41
New cards

What is debugging?

The process of finding and correcting errors in a program.

42
New cards

What is a debugger?

A program that helps in debugging by allowing step-by-step execution and inspection of variables.

43
New cards

What is the purpose of using breakpoints in debugging?

To pause execution at a certain point to inspect the state of the program.

44
New cards

What is the output of the conditional expression if num is 4?

The output will be '4 is even'.

45
New cards

What does the expression (1 > x) && (1 > x++) do?

It evaluates whether 1 is greater than x and increments x if true.

46
New cards

What is the result of the expression 3 + 4 * 4 > 5 * (4 + 3) - 1?

False, as the evaluation results in 19 > 34.

47
New cards

What is the significance of parentheses in operator precedence?

Parentheses indicate which operations should be performed first.

48
New cards

What does the expression a = b += c = 5 mean?

It means b is assigned the value of c (5), and then a is assigned the value of b.

49
New cards

What is the role of print statements in debugging?

To display variable values and execution flow to help identify errors.

50
New cards

What is the output of the switch statement when day is 2?

It will print 'Weekday'.

51
New cards

What happens in a switch statement if no case matches?

The default case is executed if it exists.

52
New cards

What is the result of the expression (num % 2 == 0) ? num + ' is even' : num + ' is odd'?

It prints whether num is even or odd based on the condition.