Java 3 (One week 8/25/24)

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

1/34

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.

35 Terms

1
New cards

Designate a boolean variable with a value for if one is greater than two.

boolean b = 1 > 2;

2
New cards

Relational operators.

Operators that compare two values, resulting in a boolean value (true or false).

3
New cards

Relational operator for less than.

<

4
New cards

Relational operator for less than or equal to

<=

5
New cards

Relational operator for greater than.

>

6
New cards

Relational operator for greater than or equal to.

>=

7
New cards

Relational operator for equal to

==

8
New cards

Relational operator for not equal to.

!=

9
New cards

Do if statements need parentheses?

Yes

10
New cards

Do if statements need braces?

No

11
New cards

If statement syntax.

if (x > y) {

//statements

}

12
New cards

If-else statement syntax.

if (x > y) {

//true statements

}

else {

//false statements

}

13
New cards
term image
knowt flashcard image
14
New cards
15
New cards

if-else if-else syntax

knowt flashcard image
16
New cards

In an if statement block, the “else” clause always matches with…

…the most recent “if“ clause in the block.

17
New cards

Nested if statement.

An if statement contained within another if statement.

18
New cards

Simplify:

if (even == true)

if (even)

19
New cards
term image
knowt flashcard image
20
New cards
<p>Write a program that computes and interprets BMI.</p><p>Test cases</p><p>70kg, 2m</p><p>80kg, 2m</p><p>100kg, 2m</p><p>200kg, 2m</p>

Write a program that computes and interprets BMI.

Test cases

70kg, 2m

80kg, 2m

100kg, 2m

200kg, 2m

70kg, 2m: Underweight

80kg, 2m: Normal

100kg, 2m: Overweight

200kg, 2m: Obese

<p>70kg, 2m: Underweight</p><p>80kg, 2m: Normal</p><p>100kg, 2m: Overweight</p><p>200kg, 2m: Obese</p>
21
New cards

Logical operator for “not“

!

22
New cards

Logical operator for “and“

&&

23
New cards

Logical operator for inclusive “or“

||

(returns true if one or both conditions are true)

24
New cards

Logical operator for exclusive “or“

^

(returns true if one condition is true, but not both)

25
New cards
term image
knowt flashcard image
26
New cards
<p>Test cases</p><p>2000: </p><p>2003: </p><p>2004: </p>

Test cases

2000:

2003:

2004:

Test cases

2000: leap year

2003: not leap year

2004: leap year

<p>Test cases</p><p>2000: leap year</p><p>2003: not leap year</p><p>2004: leap year</p>
27
New cards
term image
knowt flashcard image
28
New cards

Switch statement syntax.

knowt flashcard image
29
New cards

In a switch statement, the switch expression in parentheses must be of … data type.

char, byte, short, or int

30
New cards

In a switch statement, the case values must be of what data type?

The same data type as the switch expression.

31
New cards

The case value in a switch statement is a …1… , and therefore cannot be a …2…

1. Constant

2. Variable

32
New cards

What happens when a switch statement has no break statements?

All cases will be executed, starting with the case that matches the switch expression.

33
New cards
term image
knowt flashcard image
34
New cards
<p>express using the conditional operator:</p>

express using the conditional operator:

knowt flashcard image
35
New cards

Logic errors are also called…

bugs