All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
starting out with java from control structures
Questions and Answers of
Starting Out With Java From Control Structures
Assume x is an int variable, and rand references a Random object. What does the following statement do? x = rand.nextInt(9) + 1;
True or False: In a nested loop, the inner loop goes through all of its iterations for every iteration of the outer loop.
True or False: One limitation of the for loop is that only one variable may be initialized in the initialization expression.
What clause must you write in the header of a method that performs a file operation?
How do you open a file so that new data will be written to the end of the file’s existing data?
True or False: It is not necessary to initialize accumulator variables.
You are opening an existing file for output. How do you open the file without erasing it, and at the same time make sure that new data that is written to the file is appended to the end of the
What does it mean to append data to a file?
True or False: The for loop is a posttest loop.
Write code that does the following: opens a file named MyName.txt, reads the first line from the file and displays it, and then closes the file.
What is a potential error that can occur when a file is opened for reading?
True or False: The do-while loop is a pretest loop.
Write a program that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will
What classes do you use to read data from a file?
What does the Scanner class’s hasNext method return when the end of the file has been reached?
Write code that opens a file named NumberList.txt for writing, but does not erase the file’s contents if it already exists.
True or False: The while loop is a pretest loop.
Write code that does the following: opens a file named MyName.txt, writes your first name to the file, and then closes the file.
When writing data to a file, what is the difference between the print and the println methods?
This class allows you to read a line from a file.a. FileWriterb. Scannerc. InputFiled. FileReader
Enhance the program that you wrote for Programming Challenge 17 so it keeps a count of the number of guesses that the user makes. When the user correctly guesses the random number, the program should
What class do you use to write data to a file?
What is a file’s read position? Where is the read position when a file is first opened for reading?
This class allows you to use the print and println methods to write data to a file.a. Fileb. FileReaderc. OutputFiled. PrintWriter
What import statement will you need in a program that performs file operations?
Why should a program close a file when it’s finished using it?
Write code that does the following: opens a file named NumberList.txt, uses a loop to write the numbers 1 through 100 to the file, and then closes the file.
When a program is finished using a file, it should do this.a. Erase the fileb. Close the filec. Throw an exceptiond. Reset the read position
Write a program that asks the user to enter the amount that he or she has budgeted for a month. A loop should then prompt the user to enter each of his or her expenses for the month, and keep a
What is the difference between an input file and an output file?
How does a file buffer increase a program’s performance?
Complete the following program so it performs the following actions 10 times:• Generates a random number that is either 0 or 1.• Displays either the word “Yes” or the word “No” depending
To open a file for reading, you use the following classes.a. File and Writerb. File and Outputc. File and Inputd. File and Scanner
Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. The program should read the contents of
Why should you be careful when choosing a sentinel value?
Describe a programming problem requiring the use of nested loops.
Complete the following program so it displays a random integer in the range of 1 through 10. // Write the necessary import statement(s) here.public class ReviewQuestion15{ public static
Write nested loops to draw this pattern: # # # # # # # # # ##
To open a file for writing, you use the following class.a. PrintWriterb. FileOpenc. OutputFiled. FileReader
Write a program that asks the user for the name of a file. The program should display the contents of the file with each line preceded with a line number followed by a colon. The line numbering
In the following program segment, which variable is the loop control variable (also known as the counter variable) and which is the accumulator? int a, x = 0, y = 0;while (x < 10){ a = x
Why must the value chosen for use as a sentinel be carefully selected?
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.a. Sentinelb. Flagc. Signald. Accumulator
Write a program that asks the user for the name of a file. The program should display only the first five lines of the file’s contents. If the file contains fewer than five lines, it should display
Write nested loops to draw this pattern: * ** 米米 米米米 **. ** 米
Write a for loop that repeats seven times, asking the user to enter a number. The loop should also calculate the sum of the numbers entered.
Write a program that asks the user to enter today’s sales for five stores. The program should display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a
What is the advantage of using a sentinel?
This is a variable that keeps a running total.a. Sentinelb. Sumc. Totald. Accumulator
Write a for loop that displays every fifth number, zero through 100.
What does it mean to let the user control a loop?
Write an input validation loop that asks the user to enter the word “yes” or “no”.
Write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is where F is
This expression is executed by the for loop only once, regardless of the number of iterations.a. Initialization expressionb. Test expressionc. Update expressiond. Pre-increment expression
Write a for loop that displays all of the odd numbers, 1 through 49.
Write an input validation loop that asks the user to enter a number in the range of 1 through 4.
This type of loop always executes at least once.a. Whileb. Do-whilec. Ford. Any of these
Write a program with a loop that lets the user enter a series of integers. The user should enter −99 to signal the end of the series. After all the numbers have been entered, the program should
What is an infinite loop? Write the code for an infinite loop.
Write a for loop that displays your name 10 times.
Convert the following for loop to a while loop: for (int x = 50; x > 0; x--){ System.out.println(x + " seconds to go.");}
This type of loop has no way of ending and repeats until the program is interrupted.a. Indeterminateb. Interminablec. Infinited. Timeless
Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase (as a percentage), and
What will the following program segments display? a) for (int count = 0; count < 6; count++) System.out.println(count + count);b) for (int value = -5; value < 5;
Why is it critical that accumulator variables are properly initialized?
Convert the following while loop to a for loop: int count = 0;while (count < 50){ System.out.println("count is " + count); count++;}
The for loop is this type of loop.a. Pretestb. Posttestc. Prefixd. Postfix
Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. First the program should ask for the number of years. The outer loop will iterate
You want to write a for loop that displays “I love to program” 50 times. Assume that you will use a control variable named count.a) What initialization expression will you use?b) What test
Which loop should you use when you know the number of required iterations?
Convert the do-while loop in the following code to a while loop: Scanner keyboard = new Scanner(System.in);String input;char sure;do{ System.out.print("Are you sure you want to quit?
The do-while loop is this type of loop.a. Pretestb. Posttestc. Prefixd. Postfix
A hotel’s occupancy rate is calculated as follows: Occupancy rate = Number of rooms occupied ÷ Total number of roomsWrite a program that calculates the occupancy rate for each floor of a
Name the three expressions that appear inside the parentheses in the for loop’s header.
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?
Convert the while loop in the following code to a do-while loop: Scanner keyboard = new Scanner(System.in);int x = 1;while (x > 0){ System.out.print("Enter a number: "); x =
The while loop is this type of loop.a. Pretestb. Posttestc. Prefixd. Postfix
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character
Write an input validation loop that asks the user to enter “Yes” or “No”.
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?
Write a nested loop that displays 10 rows of '#' characters. There should be 15 '#' characters in each row.
This is a variable that controls the number of iterations performed by a loop.a. Loop control variableb. Accumulatorc. Iteration register variabled. Repetition meter
Write a program that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the
Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’.
Write a for loop that calculates the total of the following series of numbers: 2 3 + 1 + 30 29 28 i + 30 1
Describe the difference between the while loop and the do-while loop.
What is each repetition of a loop known as?a. Cycleb. Revolutionc. Orbitd. Iteration
Write an input validation loop that asks the user to enter a number in the range of 10 through 24.
Why are the statements in the body of a loop called conditionally executed statements?
Write a loop that asks the user to enter a number. The loop should iterate 10 times and keep a running total of the numbers entered.
In the expression number++, the ++ operator is in what mode?a. Prefixb. Pretestc. Postfixd. Posttest
Modify the program you wrote for Programming Challenge 2 (Distance Traveled) so it writes the report to a file instead of the screen. Open the file in Notepad or another text editor to confirm the
How many times will "I love Java programming!" be printed in the following program segment? int count = 0;while (count < 10)System.out.println("I love Java programming!);
Describe the difference between pretest loops and posttest loops.
The distance a vehicle travels can be calculated as follows: Distance = Speed * TimeFor example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a
Write a for loop that displays the following set of numbers:0, 10, 20, 30, 40, 50 ... 1000
What will the println statement in the following program segment display?int x = 5;System.out.println(++x);a. 5b. 6c. 0d. None of these
How many times will "Hello World" be printed in the following program segment? int count = 10;while (count < 1){ System.out.println("Hello World"); count++;}
Why should you indent the statements in the body of a loop?
Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again.
Showing 900 - 1000
of 1252
1
2
3
4
5
6
7
8
9
10
11
12
13