CP Chapter 5 Review.1

Ace your homework & exams now with Quizwiz!

What would be the output of program Java0505.java if 9 were entered?

Error

What library is the Scanner class located in?

The java.util package contains a library of standard Java classes, including the Scanner class.

What data types work with switch?

These are int, char and String.

Selection control structures use a special _____________ statement.

conditional

What loop structure is used with fixed iteration?

for loop structure.

Java does not use "=" to test for equality? What does it use instead?

= =

In a switch structure, what symbol separates the selection constant from the program statement that needs to be performed if a match is found.

A colon ( : )

What kind of operator is required to make an expression evaluate to true or false?

A relational operator

What would you need to change in program Java0507.java if Joe wanted the message displayed 1000 times?

Change the 60 to 1000

List the 6 relational operators.

Equals, Not equals, Less than, Greater than, Less than or equals, Greater than or equals

In fixed iteration, what does fixed mean?

Fixed means that the number of times that a program segment repeats, is fixed.

Which repetition control structures are covered on the AP® Computer Science Exam?

For, while

What is the essence of understanding, and using, control structures?

However, before we plunge into the syntax of the various conditiona statements, you need to understand the relational operators that are used by Java in the conditional statements.

With switch, can multiple cases yield the same result?

If none of the other cases are matched, Java will execute the default case.

In one-way selection, what happens if the condition is false?

If the condition is false, the program flow continues without change in the program sequence.

In one-way selection, when does the program flow branch off?

In the case of one-way selection, the true condition branches off.

While program Java0505.java compiles and executes, its output is strange. How does program Java0506.java fix the problem?

It is break, and it is placed between every case statement. break exits the current program block, which in this case means that program execution jumps to the end of the main method.

What kind of operator is "="?

Its not a complete oporator

How do you repeat multiple statements with the for loop structure?

Just like the if statement, use braces { } and block structure to control multiple program statements.

What does LCV stand for?

Loop Control Variable

What is the benefit of using loop control structures with graphics?

Loop allows many lines to be replicated without the hassle of writing out each individually.

Which selection control structures are covered on the AP® Computer Science Exam?

One-way, two-way

What is the only thing checked in a while loop?

Only the loop condition is checked.

What would be the output of program Java0506.java if 9 were entered?

September

Why is the do...while loop called a post-condition loop?

The commands for post-conditional repetition are do..while.

Give a real life situation where fixed iteration is not practical.

The entry of a password can be correct the first time or it may take many repeated attempts before the correct password is entered.

Where must the loop counter be initialized when using a while loop?

The for loop includes a component in the loop heading that increments the loop counter by some specified amount.

The while loop structure requires a statement inside the loop body that was not necessary with the for loop. What is the purpose of this statement?

The purpose of this statement is to give an opportunity for the loop control variable to change.

In two-way selection, what happens if the condition is false?

The two-way selection structure selects one direction, or the other direction, but not both.

What do Selection and Repetition control structures have in common?

The value of the condition determines if the program flow will "branch off" from the main program sequence.

What must happen inside a while loop?

The while loop structure requires a statement inside the loop body that was not necessary with the for loop.

What would be the output of program Java0506.java if 0 were entered?

This is not a valid month number.

What kind of loop is the while loop?

This loop is called a precondition loop.

Assume the condition for a do...while loop is already false, even before the loop begins. Furthermore, assume nothing in the loop will ever make the condition change to true. How many times will the loop execute?

This program will not compile.

Assume the condition for a while loop is already false, even before the loop begins. How many times will the loop execute?

This program will not compile.

Which control structure is used in the most with graphics programs in this chapter?

With the help of a control structure you can draw many lines with a single drawLine statement.

What is the main concern in using graphics commands with control structures?

You can also perform some neat tricks by using control structures. Control structures combined with graphic method calls can have some very nice visual effects.

What are 2 synonyms for Repetition?

You can also say looping, and the formal computer science word is iteration.

Most conditional statements will require what?

a relational operator.

How does Simple Sequence work?

alone is not very satisfactory for programs of any type of consequence.

How do you control multiple statements with switch?

command which uses a selection variable with a value

What are 2 synonyms for Selection?

conditional branching or decision making.

A for loop is not well suited for something like entering a password. Both the while loop and the do...while loop would work in this case. If you were writing a password program, which loop structure would you chose? Explain the reasoning behind your answer.

do...while

Does Multi-way Selection use a conditional statement?

does not use the conditional statement logic of the if structures

What does program flow follow?

follows the exact sequence of listed program statements, unless directed otherwise by a Java control structure.

Why is a prompt necessary for program input?

gives the program user an indication what is happening

Write the Java statement that will do this action: If your grade is 70 or better, print "You passed!" otherwise print "You failed!"

if (grade >= 70) System.out.println("You passed"); else System.out.println("You failed!");

What statement is used with if for two-way selection?

if the condition is true execute the first program statement or first block else if the condition is not true execute the second program statement or second block

Programs in what computer language require control structures?

in any computer language

What does the j++ mean?

indicates the manner in which the Loop Control Variable is altered. In this case the value of j is incremented by 1 each time through the loop.

What does the j = 1 mean?

initializes the Loop Control Variable (LCV), which in this case means that j starts with the value of 1.

All conditions must be placed inside what?

inside parentheses

Explain Multiple-Way Selection.

is a little different from one-way and two-way selection. In this control structure the condition is not very explicit.

What is a conditional statement?

is a program expression, which evaluates to true or false.

Must the loop counter in a for statement be an int?

no

What are the 3 types of Selection?

one-way, two-way and multiple-way

What are the 3 general types of control structures?

simple sequence, selection, and repetition

What does the j <= 100 mean?

states the Loop Entry Condition. As long as the value of j is less than or equal to 40, the program statement following the for parenthesis will be executed.

Explain Repetition.

this is a control structure that executes certain program segments repeatedly.

How do you control multiple program statements with one-way or two-way selection?

two-way selection

When is the default statement executed?

when nothing is specified.

Which loop structure would be good if you wanted to display 50 rectangles on the screen?

while

What does the nextInt method do?

will stop the program execution and then sit still patiently waiting for the input of an integer value from the keyboard.

Explain how Multi-way Selection is accomplished in Java.

with the switch command which uses a selection variable with a value.


Related study sets

Chapter 3 Test Review Part 2-Spanish

View Set

Unit 20. Vocab. A. Choose the correct word.

View Set

Ap Human 3A Quiz (from Barron's 9th Edition)

View Set

ATI Introduction to Health Assessment Test

View Set

Chapter 16 reading quiz questions

View Set

Words of similar meaning - Adjectives

View Set

ALL Chapters 1-5 Strategic Management Exam Practice

View Set

Ch 2 Test Review Criminal Justice Molenar

View Set