Module 3: Decision Structure Flashcards

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
Q

Can relational operators (==, >=, etc) be used to test character data?

A

Yes

26
Q

What will you use to compare String objects?

A

A String method

27
Q

To compare the contents of two String objects correctly, use the String class’s equals method.

A

StringReference1.equals(StringReference2)

28
Q

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.

A

StringReference.compareTo(OtherString)

29
Q

What does the compareTo method return?

A

It returns an integer value.

30
Q

What does it mean if the method’s return value is negative?

A

StringReference is less than Other String.

31
Q

What does it mean if the method’s return value is zero?

A

The two strings are equal.

32
Q

What does it mean if the method’s return value is positive?

A

StringReference is greater than OtherString

33
Q

Used to create a decision structure, which allows a program to
have more than one path of execution.

A

The If Statement

34
Q

Causes one or more statements to execute only when a boolean
expression is true.

A

The If Statement

35
Q

import java.util.scanner;

A

To import the scanner class.

36
Q

Scanner input = new Scanner(System.in);
String color = input.nextLine;

A

“input” is the name of the class

37
Q

Lets the value of a variable or expression determine where the
program will branch to.

A

The Switch Statement

38
Q

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.

A

The Switch Statement

39
Q

Allows you to format output in a variety of ways.

A

System.out.printtf(FormatString, ArgumentList);

40
Q

String that contains text, special formatting specifiers, or both.

A

Optional and can be used to perform actions when none of
the specified cases matches the switch-expression.

41
Q

Statement that immediately ends the switch statement.

A

break

42
Q

optional, can be used to perform actions when none of
the specified cases matches the switch-expression.

A

default

43
Q

What is the general format for the system.out.printtf method?

A

System.out.printf(FormatString, ArgumentList)

44
Q

Allows you to format output in a variety of ways.

A

System.out.printtf

45
Q

What would the output be?

int dogs = 2;
int cats = 4;

System.out.printtf(“We have %d dogs and %d cats \n”, dogs, cats)”

A

Output: We have 2 dogs and 4 cats

46
Q

All format specifiers begin with what?

A

%

47
Q

They cause the value to be formatted in a variety of ways in a format specifier.

A

Flags

48
Q

You can optionally specify the minimum field width for
the value.

A

Width

49
Q

All format specifiers must end with a conversion character, such as f (%f)
for floating-point, or d (%d) for decimal integer

A

Conversion

50
Q

You can change the number of decimal points that are displayed

A

Precision

51
Q

What would the output be?

double temp = 78.42819;
System.out.printf(“The temperature is %2f degrees.\n”, temp);

A

Output: The temperature is 78.4 degrees.

52
Q

What will happen if you specify a precision with the %d format specifier?

A

An error at runtime will occur because precision can only be specified with floating-point values

53
Q

The minimum
number of spaces that should be used to display the value

A

Minimum Field Width

54
Q

What would the output be?

double number = 12345.6789;
System.out.printf(“The number is:%20f\n”, number);

A

Output: The number is: 12345.678900

55
Q

Comma Separator
What would the output be?

double amount = 1234567.89;
System.out.printf(“The value is %,f\n”, amount);

A

Output : The value is 1,234,567.890000

56
Q

Adding numbers with Leading Zeros
What would the output be?

double number = 123.4;
System.out.printf(“The number is:%08.1f\n “, number);

A

Output: The number is: 1,234,567.890000

57
Q

%[flags][width][.precision]conversion

A

General format for format specifiers.

58
Q

What happens if the break statement is omitted?

A

The program would execute all of the lines from the matching case statement to the end other block.

59
Q

can be assigned a value only once, and then it cannot be
changed later in the program.

A

Named Constant

60
Q

What is the keyword preceding a named constant in its declaration statement?

A

final