Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
11th Edition
ISBN: 9780134671604
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 12.13, Problem 12.13.2CP
Simplify the code in lines 20-28 as follows: 1. Delete lines 20 and 28; 2. Add an additional condition !listOfPendingURLs.contains(s) to the if statement in line 25. Write the complete new code for the while loop in lines 20-29. Does this revision work?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3. Create an ArrayList of strings to store the names of celebrities or athletes. Add five names to the list. Process the list with a for loop and the get() method
to display the names, one name per line. Pass the list to avoid method. Inside the method, Insert another name at index 2 and remove the name at index 4.
Use a foreach loop to display the arraylist again, all names on one line separated by asterisks. After the method call in main, create an iterator for the
arraylist and use it to display the list one more time. See Sample Output.
SAMPLE OUTPUT
Here is the list
Lionel Messi
Drake
Adele
Dwayne Johnson
Beyonce
Here is the new list
* Lionel Messi * Drake * Taylor Swift * Adele * Beyonce
Using an iterator, here is the list
Lionel Messi
Drake
Taylor Swift
Adele
Beyonce
The for construct is a loop used to iterate through a sequence of items. So long as there are things to process, it will continue to operate. Could you please tell me whether this statement is true or false?
Loop through the items in the dayslist.
Chapter 12 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
Ch. 12.2 - Prob. 12.2.1CPCh. 12.2 - Prob. 12.2.2CPCh. 12.2 - Prob. 12.2.3CPCh. 12.2 - Prob. 12.2.4CPCh. 12.2 - Prob. 12.2.5CPCh. 12.2 - Show the output of the following code:Ch. 12.3 - Prob. 12.3.1CPCh. 12.3 - Prob. 12.3.2CPCh. 12.4 - Prob. 12.4.1CPCh. 12.4 - Prob. 12.4.2CP
Ch. 12.4 - Prob. 12.4.3CPCh. 12.4 - Prob. 12.4.4CPCh. 12.4 - Prob. 12.4.5CPCh. 12.4 - Prob. 12.4.6CPCh. 12.4 - What is displayed when running the following...Ch. 12.4 - Prob. 12.4.8CPCh. 12.4 - What does the method getMessage() do?Ch. 12.4 - What does the method printStackTrace() do?Ch. 12.4 - Prob. 12.4.11CPCh. 12.4 - Prob. 12.4.12CPCh. 12.5 - Prob. 12.5.1CPCh. 12.6 - Prob. 12.6.1CPCh. 12.7 - Prob. 12.7.1CPCh. 12.8 - Prob. 12.8.1CPCh. 12.9 - Prob. 12.9.1CPCh. 12.9 - Prob. 12.9.2CPCh. 12.10 - What is wrong about creating a File object using...Ch. 12.10 - How do you check whether a file already exists?...Ch. 12.10 - Can you use the File class for I/O? Does creating...Ch. 12.11 - Prob. 12.11.1CPCh. 12.11 - Prob. 12.11.2CPCh. 12.11 - Prob. 12.11.3CPCh. 12.11 - Prob. 12.11.4CPCh. 12.11 - What will happen if you attempt to create a...Ch. 12.11 - Prob. 12.11.6CPCh. 12.11 - Suppose you enter 45 57, 8 789, then press the...Ch. 12.11 - Prob. 12.11.8CPCh. 12.12 - How do you create a Scanner object for reading...Ch. 12.13 - Prob. 12.13.1CPCh. 12.13 - Simplify the code in lines 20-28 as follows: 1....Ch. 12 - Prob. 12.1PECh. 12 - (InputMismatchException) Write a program that...Ch. 12 - (ArrayIndexOutOfBoundsException) Write a program...Ch. 12 - (IllegalArgumentException) Modify the Loan class...Ch. 12 - (IllegalTriangleException) Programming Exercise...Ch. 12 - (NumberFormatException) Listing 6.8 implements the...Ch. 12 - Prob. 12.7PECh. 12 - Prob. 12.8PECh. 12 - Prob. 12.9PECh. 12 - Prob. 12.10PECh. 12 - Prob. 12.11PECh. 12 - (Reformat Java source code) Write a program that...Ch. 12 - (Count characters, words, and lines in a file)...Ch. 12 - (Process scores in a text file) Suppose a text...Ch. 12 - (Write/read data) Write a program to create a file...Ch. 12 - Prob. 12.16PECh. 12 - (Game: hangman) Rewrite Programming Exercise 7.35....Ch. 12 - Prob. 12.18PECh. 12 - (Count words) Write a program that counts the...Ch. 12 - Prob. 12.20PECh. 12 - (Data sorted?) Write a program that reads the...Ch. 12 - Prob. 12.22PECh. 12 - (Process scores in a text file on the Web) Suppose...Ch. 12 - (Create large dataset) Create a data file with...Ch. 12 - (Create a directory) Write a program that prompts...Ch. 12 - Prob. 12.26PECh. 12 - (Replace words) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have several files in a...Ch. 12 - (Occurrences of each letter) Write a program that...Ch. 12 - (Baby name popularity ranking) The popularity...Ch. 12 - (Ranking summary) Write a program that uses the...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (8th Edition)
In Exercises 41 through 46, identify the errors.
Introduction To Programming Using Visual Basic (11th Edition)
The resistance and inductance of the circuit in Fig. 8.5 are 100 and 20 mH, respectively.
Find the value of C t...
Electric Circuits. (11th Edition)
Describe two properties that each candidate key must satisfy.
Modern Database Management
Why might resistance welding be considered a form of solid-state welding?
Degarmo's Materials And Processes In Manufacturing
Write Python code that prompts the user to enter his or her favorite color and assigns the users input to a var...
Starting Out with Python (4th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 7-Write a procedure that returns the list that contains everything except for the last two elements of the given (nonempty) list. For example, (last-element' ((a b) c d (e))) returns ((a b) c). Then, Manually trace your procedure with the provid- ed example. Please study provided examples in the lecture notes to learn how you should manually trace our procedure.arrow_forwardQ.Create an interesting educational information chat box that asks the user to give an input question and then answers the question given by user with a suitable answer. You can make use of list for different questions and answers.Save two to three answers for a single question and then for random selection of elements from those answers use random choice(list) method from random module that returns a random element. Also for a user question that doesn't matches with the questions present in the chat box it should display statement like "oops i can't answer that" "sorry i am not intelligent enough" "could u please ask something else" using random method so that every time one of these statements appear **coding language python ***try using basic programming techniques in python without using arrays and pointers * * * copy paste the program itself and also the screenshot of program and output * * * use any type of data for questions such as name details of cities species etc depends on…arrow_forwardWrite a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1. Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int courseGrades[4]). Also note: If the submitted code tries to access an invalid array element, such as courseGrades[9] for a 4-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. #include <iostream>using namespace std; int main() { const int NUM_VALS = 4; int courseGrades[NUM_VALS]; int i; for (i = 0; i < NUM_VALS; ++i) { cin >> courseGrades[i]; } /* Your solution goes…arrow_forward
- Thank you, I understand how the code is executed. The problem is that I'm only allowed to use either a for loop, or list comprehension to achieve the result. Is there any way to do so without implementing the "join" function or method, as I have not learned that in class yet. Here is the exact requirements: use another for loop to print all grades in the grades list for the course. Use a format identifier to allow for printing of a right-justified grade with a width of 4 followed by a percent sign Is there any way to only use f strings, for loops, and/or list comprehension to achieve the same result. Thank youarrow_forward//arrow_forwardTask 2 Get Binary 1: Implement the get_bin_1 function as directed in the comment above the function. If the directions are unclear, run the code, and look at the expected answer for a few inputs. In order to be able to compare your solution to the answer, you cannot simply print out the binary directly to the console. Instead, you have been provided with a very rudimentary stringbuilder implementation that allows you to build a string one character at a time, without the ability to erase. There are comments at the top of the code explaining how to use the stringbuilder, however you could also see how it is being used in task_2_check. Note: if you create a stringbuilder and append ‘a’, ‘b’, then ‘c’, the resulting string will be “abc” when printed. You are free to read through the stringbuilder implementation, but it is quite complicated in order to make it easy to use. As specified in the comment, you may not use division (/) or mod (%) to implement this function (as the check…arrow_forward
- Come up with a nested loop that prints the following table of numbers out. Don’t worry about getting the columns lined up properly (you can use \t after each number to help). 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 This is effectively a multiplication table, where each number is its row number * its column number. To get this, you can take the 1 2 3 4 example pattern from the slides and modify it. Make it 5 rows instead of 4 and adjust the columns to print 1-5 instead of 1-4. Lastly, modify the print statement to print the row number * the column number instead.arrow_forwardWrite a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10), print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1. Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int courseGrades[4]). Also note: If the submitted code tries to access an invalid array element, such as courseGrades[9] for a 4-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. 1 #include HNm in 10 m DO G 2 3 int main(void) { 4 5 6 const int NUM_VALS = 4; int courseGrades [NUM_VALS]; int i; 7 8 for (i = 0; i < NUM_VALS; ++i) { scanf("%d", &(courseGrades[i])); 9 } 10 11 12 13 14 15 } /*Your solution…arrow_forwardWhat happens when you add an entry into position 4 into a List? Select one: a. If the List has 4 or more entries, entries in positions 4 and up will move over 1 spot to make room for the new entry to be added to position 4 b. All of these c. If the List has 2 or fewer entries, an IndexOutOfBoundsExecption is thrown d. If the List has exactly 3 entries, the new entry will be added to the end of the Listarrow_forward
- The for construct is a kind of loop that iteratively processes a sequence of items. So long as there are things to process, it will continue to operate. In your opinion, how true is this statement?arrow_forwardDo a trace on the for loop below, and show each iteration of the loop in the tracing table until the loop finishes. Each row in the table corresponds to one iteration of the for loop. int j=3, k=2; for(int i = 12; i >7; i--){ k = k + j - - * i ; } The tracing table is here: i i > 7 j karrow_forward7-Write a procedure that returns the list that contains everything except for the last element of the given (nonempty) list. For example, (last-element ‘(a (b c ) (d)) ) returns (a (b c)). For example, (last-element ‘(a (b c ) (d) ) ) returns (a (b c)) . Then, Manually trace your procedure with the provided example.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
C++ Programming Tutorial 36 - Intro to Loops; Author: Caleb Curry;https://www.youtube.com/watch?v=M3o7Y0juEP0;License: Standard YouTube License, CC-BY