Module 3: Decision Structure Flashcards

(60 cards)

1
Q

An operator that determines whether a specific relationship exist between two
values.

A

The Relational Operator

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

Operator for greater than

A

>

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

Operator for less than

A

<

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

Operator for greater than or equal to

A

> =

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

Operator for less than or equal to

A

<=

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

Operator for equal to

A

==

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

Operator for not equal to

A

!=

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

Explain the difference between == and =

A

The double equal(==) is a relational operator which can use for comparison. The
boolean expression have a value of true or false. While the single equal (=) is an
assignment operator that uses to assign a value to the variable

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

What is the value of the following expression?

int a = 5
a == 10

A

False

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

int a = 5
a = 10

A

The value of a is simply changed to 10.

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

How many variables does the left side of an expression must have when using the assignment operator?

A

Only single variable

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

Which one is valid?
a. c = 5
b. c+d= 5

A

a is valid, b is invalid.

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

Also known as Boolean operators, operate on Boolean values to
create a new Boolean value.

A

Logical Operator

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

Sometimes, a statement is executed is determined by a combination of
several conditions. What can you use to combine these conditions?

A

Logical Operator

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

What is the name of the ! operator?

A

not

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

Rule of the ! operator

A

Opposite of the expression

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

Name of && operator

A

And

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

Rules of && operator

A

One false, all false

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

Name of || operator

A

Or

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

Rules of || operator

A

One true, all true

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

What would be the result?

20 > 18 && 49 < 50

A

20 > 18 = True
49 < 50 = True
The expression uses the && operator (one false, all false). Therefore the result is true.

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

What would be the result?
kg = 49
age = 20

20 > 30 || 49 < 51

A

20 > 30 = False
49 < 51 = True

The expression uses the || operator (one true, all true). Therefore, the result is true.

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

What is the precedence of the logical operators?

A

AND (&&) - Highest
OR (||)
NOT (!) - Lowest

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

What would be the result of the following expression?

!(3>4)|| !(12>4) && !(4>1)

A

!(3>4)|| !(12>4) && !(4>1)
!(False) || !(True) && !(True)
True || False && False
True || False
True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Can relational operators (==, >=, etc) be used to test character data?
Yes
26
What will you use to compare String objects?
A String method
27
To compare the contents of two String objects correctly, use the String class's equals method.
StringReference1.equals(StringReference2)
28
The String class also provides the compareTo method, which can be used to determine whether one string is greater than, equal to, or less than another string.
StringReference.compareTo(OtherString)
29
What does the compareTo method return?
It returns an integer value.
30
What does it mean if the method's return value is negative?
StringReference is less than Other String.
31
What does it mean if the method's return value is zero?
The two strings are equal.
32
What does it mean if the method's return value is positive?
StringReference is greater than OtherString
33
Used to create a decision structure, which allows a program to have more than one path of execution.
The If Statement
34
Causes one or more statements to execute only when a boolean expression is true.
The If Statement
35
import java.util.scanner;
To import the scanner class.
36
Scanner input = new Scanner(System.in); String color = input.nextLine;
"input" is the name of the class
37
Lets the value of a variable or expression determine where the program will branch to.
The Switch Statement
38
Is a multiple alternative decision structure. It allows you to test the value of a variable or an expression and then use that value to determine which statement or set of statements to execute.
The Switch Statement
39
Allows you to format output in a variety of ways.
System.out.printtf(FormatString, ArgumentList);
40
String that contains text, special formatting specifiers, or both.
Optional and can be used to perform actions when none of the specified cases matches the switch-expression.
41
Statement that immediately ends the switch statement.
break
42
optional, can be used to perform actions when none of the specified cases matches the switch-expression.
default
43
What is the general format for the system.out.printtf method?
System.out.printf(FormatString, ArgumentList)
44
Allows you to format output in a variety of ways.
System.out.printtf
45
What would the output be? int dogs = 2; int cats = 4; System.out.printtf("We have %d dogs and %d cats \n", dogs, cats)"
Output: We have 2 dogs and 4 cats
46
All format specifiers begin with what?
%
47
They cause the value to be formatted in a variety of ways in a format specifier.
Flags
48
You can optionally specify the minimum field width for the value.
Width
49
All format specifiers must end with a conversion character, such as f (%f) for floating-point, or d (%d) for decimal integer
Conversion
50
You can change the number of decimal points that are displayed
Precision
51
What would the output be? double temp = 78.42819; System.out.printf("The temperature is %2f degrees.\n", temp);
Output: The temperature is 78.4 degrees.
52
What will happen if you specify a precision with the %d format specifier?
An error at runtime will occur because **precision can only be specified with floating-point values**
53
The minimum number of spaces that should be used to display the value
Minimum Field Width
54
What would the output be? double number = 12345.6789; System.out.printf("The number is:%20f\n", number);
Output: The number is: 12345.678900
55
Comma Separator What would the output be? double amount = 1234567.89; System.out.printf("The value is %,f\n", amount);
Output : The value is 1,234,567.890000
56
Adding numbers with Leading Zeros What would the output be? double number = 123.4; System.out.printf("The number is:%08.1f\n ", number);
Output: The number is: 1,234,567.890000
57
%[flags][width][.precision]conversion
General format for format specifiers.
58
What happens if the break statement is omitted?
The program would execute all of the lines from the matching case statement to the end other block.
59
can be assigned a value only once, and then it cannot be changed later in the program.
Named Constant
60
What is the keyword preceding a named constant in its declaration statement?
final