Nội dung chính Show
- What is the difference between pretest loops and posttest loops?
- What is the difference between a pretest and a posttest?
- What is the difference between a pretest loop and a posttest loop give an example of each loop?
- Which loop is the posttest loop?
Service Management: Operations, Strategy, and Information Technology
7th EditionJames Fitzsimmons, Mona Fitzsimmons
103 solutions
Information Technology Project Management: Providing Measurable Organizational Value
5th EditionJack T. Marchewka
346 solutions
Introduction to Algorithms
3rd EditionCharles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
720 solutions
Fundamentals of Database Systems
7th EditionRamez Elmasri, Shamkant B. Navathe
687 solutions
Recommended textbook solutionsIntroduction to Algorithms
3rd EditionCharles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
720 solutions
Information Technology Project Management: Providing Measurable Organizational Value
5th EditionJack T. Marchewka
346 solutions
Fundamentals of Database Systems
7th EditionRamez Elmasri, Shamkant B. Navathe
687 solutions
Information Technology Project Management: Providing Measurable Organizational Value
5th EditionJack T. Marchewka
346 solutions
Upgrade to remove ads
Only SGD 41.99/year
Flashcards
Learn
Test
Match
Flashcards
Learn
Test
Match
Terms in this set (49)
What will the println statement in the following program segment
display?
int x = 5;
System.out.println(x++);
5
What will the println statement in the following program segment display?
int x = 5;
System.out.println(++x);
6
In the expression number++, the operator ++ is in what mode?
postfix
What is each repetition of a loop known as?
iteration
This is a variable that controls the number of iterations performed by a loop.
loop control variable
The while loop is this type of loop.
pretest
The do-while loop is this type of loop.
posttest
The for loop is this type of loop.
pretest
This type of loop has no way of ending and repeats until the program is interrupted.
infinite
This type of loop always executes at least once.
do-while
This expression is executed by the for loop only once, regardless of the number of iterations.
initialization expression
This is a variable that keeps a running total.
accumulator
This is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list.
sentinel
To open a file for writing, you use the following class.
PrintWriter
To open a file for reading, you use the following classes.
File and Scanner
When a program is finished using a file, it should do this.
Close the file
This class allows you to use the print and println methods to write data to a file.
PrintWriter
This class allows you to read a line from a file.
Scanner
The while loop is a pretest loop.
True
The do-while loop is a pretest loop.
False
The for loop is a posttest loop.
False
It is not necessary to initialize accumulator variables.
False
One limitations of the for loop is that only one variable may be initialized in the initialization expression.
False
A variable may be defined in the initialization expression of the for loop.
True
In a nested loop, the inner loop goes through all of its iterations for every iteration of the outer loop.
True
To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.
False
Briefly describe the difference between the prefix and postfix modes used by the increment and decrement operators.
In postfix mode the operator is placed after the operand. In prefix mode the operator is placed before the variable operand. Postfix mode causes the increment or decrement operation to happen after the value of the variable is used in the expression. Prefix mode causes the increment or decrement to happen first.
Why should you indent the statements in the body of a loop?
A pretest loop tests its condition before each iteration. A posttest loop tests its condition after each iteration. A posttest loop will always execute at least once.
Describe the difference between pretest loops and posttest loops.
A pretest loop tests its test expression before each iteration. A posttest loop tests its test expression after each iteration.
Why are the statements in the body of a loop called conditionally executed statements?
Because the loop executes them only under the condition that its test expression is true.
Describe the difference between the while loop and the do-while loop.
The while loop is a pretest loop and the do-while loop is a posttest loop.
Which loop should you use in situations where you want the loop to repeat until the boolean expression is false, and the loop should not execute if the test expression is false to begin with?
The while loop.
Which loop should you use in situations where you want the loop to repeat until the boolean expression is false, but the loop should execute at least once?
The do-while loop.
Which loop should you use when you know the number of required iterations?
The for loop.
Why is it critical that accumulator variables are properly initialized?
An accumulator is used to keep a running total of numbers. In a loop, a value is usually added to the current value of the accumulator. If it is not properly initialized, it will not contain the correct total.
What is an infinite loop? Write the code for an infinite loop.
A loop that has no way of stopping. Here is an example:
int x = 1;
while (x > 0)
System.out.println("Hello");
Describe a programming problem that would require the use of an accumulator.
There are many possible examples. A program that asks the user to enter a business's daily sales for a number of days, and then displays the total sales is one example.
What does it mean to let the user control a loop?
The loop terminates after the user has entered a specific value.
What is the advantage of using a sentinel?
Sometimes the user has a list of input values that is very long, and doesn't know the number of items there are. When the sentinel value is entered, it signals the end of the list, and the user doesn't have to count the number of items in the list.
Why must the value chosen for use a sentinel be carefully selected?
So it cannot be mistaken as a member of the list.
Describe a programming problem requiring the use of nested loops.
There are many possible examples. One example is a program that asks for the average temperature for each month, for a period of five years. The outer loop would iterate once for each year and the inner loop would iterate once for each month.
How does a file buffer increase a program's performance?
When a program writes data to a file, that data is first written to the buffer. When the buffer is filled, all the information stored there is written to the file. This technique increases the system's performance because writing data to memory is faster than writing it to a disk.
Why should a program close a file when it's finished using it?
Closing a file writes any unsaved data remaining in the file buffer.
What is a file's read position? Where is the read position when a file is first opened for reading?
The read position is the position of the next item to be read. When the file is opened, its read position is set to the first item in the file.
When writing data to a file, what is the difference between the print and the println methods?
After the println method writes its data, it writes a newline character. The print method does not write the newline character.
What does a scanner class's hasNext method return when the end of the file has been reached?
false
What is a potential error that can occur when a file is opened for reading?
The file does not exist.
What does it mean to append data to a file?
To write the data to the end of the file's existing contents.
How do you open a file so that new data will be written to the end of the file's existing data?
You create an instance of the FileWriter class to open the file. You pass the name of the file (a string) as the constructor's first argument, and the boolean value true as the second argument. Then, when you create an instance of the PrintWriter class, you pass a reference to the FileWriter object as an argument to the PrintWriter constructor. The file will not be erased if it already exists and new data will be written to the end of the file.
Sets with similar termsChapter 4 Java Loops and Files
84 terms
NightCloudSurfer
Chapter 5
46 terms
cboyer1996
Java chapter 4
26 terms
waking19
Chapter 5: Starting out with C++ Definitions
44 terms
carolina_ramirez520
Sets found in the same folderTest 2 review
40 terms
orc_mischiefPLUS
Chapter 9 review
40 terms
orc_mischiefPLUS
CPS Chapter 3 MC/TF/Short Answer
31 terms
abbyxm17
Chapter 7 review
48 terms
orc_mischiefPLUS
Other sets by this creatorFinal Exam - Intro to Neuro
87 terms
abbyxm17
Dev. Psych - Exam 3
57 terms
abbyxm17
Human Phys Unit 5
2 terms
abbyxm17
Human Phys Exam 4 Practice Questions
17 terms
abbyxm17
Verified questionsCOMPUTER SCIENCE
A design technique that helps to reduce the duplication of code within a program and is a benefit of using functions is __________. a. code reuse b. divide and conquer c. debugging d. facilitation of teamwork
Verified answer
COMPUTER SCIENCE
The kth quantiles of an n-element set are the k - 1 order statistics that divide the sorted set into k equal-sized sets (to within 1). Give an O(n lg k)-time algorithm to list the kth quantiles of a set.
Verified answer
COMPUTER SCIENCE
Give implementation-level descriptions of Turing machines that decide the following languages over the alphabet {0,1}. $^\mathrm{A}{\mathrm{a}}$. {w| w contains an equal number of 0s and 1s}, b. {w| w contains twice as many 0s as 1s}, c. {w| w does not contain twice as many 0s as 1s}.
Verified answer
COMPUTER SCIENCE
Object is to class as a. circle is to square, b. house is to blueprint, c. blueprint is to house, d. bicycle is to car, e. car is to bicycle.
Verified answer
Recommended textbook solutionsInformation Technology Project Management: Providing Measurable Organizational Value
5th EditionJack T. Marchewka
346 solutions
Fundamentals of Database Systems
7th EditionRamez Elmasri, Shamkant B. Navathe
687 solutions
Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th EditionDavid A. Patterson, John L. Hennessy
220 solutions
Introduction to the Theory of Computation
3rd EditionMichael Sipser
389 solutions
Other Quizlet setsBio Exam 3 Study Guide
77 terms
elhombreverde
Miriam Lines
78 terms
WAveri1
Quiz Questions
45 terms
zbuanno
Related questionsQUESTION
Which HTML tag should you use to define a hot spot region on an image map ?
15 answers
QUESTION
int b [9999] = {23}; will initialize all elements of the array b to 23
2 answers
QUESTION
In HTML, JavaScript code must be inserted between <script> and </script> tags.
2 answers
QUESTION
What operator could be used if you wanted to constantly query the Bitcoin API but then stop once it reached a certain value?
2 answers
What is the difference between pretest loops and posttest loops?
pretest loop: A loop that tests the condition before each iteration. posttest loop: A loop that tests the condition after each iteration.
What is the difference between a pretest and a posttest?
Typically, a pretest is given to students at the beginning of a course to determine their initial understanding of the measures stated in the learning objectives, and posttest is conducted just after completion of the course to determine what the students have learned.
What is the difference between a pretest loop and a posttest loop give an example of each loop?
the statements in Do/Loop are skipped. is executed at least once, since the condition is at the bottom of the loop. ... Explain difference between a pretest and a posttest in a Do/Loop..
Which loop is the posttest loop?
The do-while loop is a posttest loop. This means it does not test its expression until it has completed an iteration. As a result, the do-while loop always performs at least one iteration, even if the expression is false to begin with.