Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 18.6, Problem 18.6.6CP
Will the program work if lines 20 and 21 are replaced by the following code?
for (File file: files)
size += getSize(file); // Recursive call
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
please code in python
Forbidden concepts: arrays/lists (data structures), recursion, custom classes
Create a program that takes a password string from the user and encrypts the letters to go up or down the alphabet using a triple-number key. The amount up or down for the encryption of the alphabetical characters will depend on the input from the user.
Input for the encryption key integers will be -25 ≤ key ≤ 25.For example, ‘CHICKEN’ with a 1, 2, -3 would be C up 1 to D, H up 2 to J, I down 3 to F,then C up 1 to D, K up 2 to M, E down 3 to B, and N up 1 to O. Thus the encryption becomes ‘DJFDMBO’.
Answer properly
In C++
Write a recursive function that displays a string reversely on the console using the following header:void reverseDisplay(const string& s) For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.
Chapter 18 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 18.2 - What is a recursive method? What is an infinite...Ch. 18.2 - Prob. 18.2.2CPCh. 18.2 - Show the output of the following programs and...Ch. 18.2 - Prob. 18.2.4CPCh. 18.2 - Prob. 18.2.5CPCh. 18.2 - Write a recursive mathematical definition for...Ch. 18.3 - Prob. 18.3.1CPCh. 18.3 - What is wrong in the following methods?Ch. 18.3 - Prob. 18.3.3CPCh. 18.4 - Describe the characteristics of recursive methods.
Ch. 18.4 - Prob. 18.4.2CPCh. 18.4 - Prob. 18.4.3CPCh. 18.5 - Prob. 18.5.1CPCh. 18.5 - Prob. 18.5.2CPCh. 18.5 - What is a recursive helper method?Ch. 18.6 - Prob. 18.6.1CPCh. 18.6 - How does the program get all files and directories...Ch. 18.6 - How many times will the getSize method be invoked...Ch. 18.6 - Will the program work if the directory is empty...Ch. 18.6 - Will the program work if line 20 is replaced by...Ch. 18.6 - Will the program work if lines 20 and 21 are...Ch. 18.7 - Prob. 18.7.1CPCh. 18.8 - Prob. 18.8.1CPCh. 18.8 - Prob. 18.8.2CPCh. 18.8 - How many times is the displayTriangles method...Ch. 18.8 - Prob. 18.8.4CPCh. 18.8 - Prob. 18.8.5CPCh. 18.9 - Which of the following statements are true? a. Any...Ch. 18.9 - Prob. 18.9.2CPCh. 18.10 - Identify tail-recursive methods in this chapter.Ch. 18.10 - Rewrite the fib method in Listing 18.2 using tail...Ch. 18 - Prob. 18.1PECh. 18 - Prob. 18.2PECh. 18 - (Compute greatest common divisor using recursion)...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Fibonacci series) Modify Listing 18.2,...Ch. 18 - Prob. 18.8PECh. 18 - (Print the characters in a string reversely) Write...Ch. 18 - (Occurrences of a specified character in a string)...Ch. 18 - Prob. 18.11PECh. 18 - (Print the characters in a string reversely)...Ch. 18 - (Find the largest number in an array) Write a...Ch. 18 - (Find the number of uppercase letters in a string)...Ch. 18 - Prob. 18.15PECh. 18 - (Find the number of uppercase letters in an array)...Ch. 18 - (Occurrences of a specified character in an array)...Ch. 18 - (Tower of Hanoi) Modify Listing 18.8,...Ch. 18 - Prob. 18.19PECh. 18 - (Display circles) Write a Java program that...Ch. 18 - (Decimal to binary) Write a recursive method that...Ch. 18 - (Decimal to hex) Write a recursive method that...Ch. 18 - (Binary to decimal) Write a recursive method that...Ch. 18 - (Hex to decimal) Write a recursive method that...Ch. 18 - Prob. 18.25PECh. 18 - (Create a maze) Write a program that will find a...Ch. 18 - (Koch snowflake fractal) The text presented the...Ch. 18 - (Nonrecursive directory size) Rewrite Listing...Ch. 18 - (Number of files in a directory) Write a program...Ch. 18 - (Game: Knights Tour) The Knights Tour is an...Ch. 18 - (Game: Knights Tour animation) Write a program for...Ch. 18 - (Game: Eight Queens) The Eight Queens problem is...Ch. 18 - Prob. 18.35PECh. 18 - (Sierpinski triangle) Write a program that lets...Ch. 18 - (Hilbert curve) The Hilbert curve, first described...Ch. 18 - (Recursive tree) Write a program to display a...Ch. 18 - Prob. 18.39PE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Where do you declare class-level variables?
Starting Out With Visual Basic (8th Edition)
If a function has a local variable with the same name as a global variable, only the _______ variable can be se...
Starting Out with C++ from Control Structures to Objects (9th Edition)
2-1 List the five types of measurements that form the
basis of traditional ptane surveying-
Elementary Surveying: An Introduction To Geomatics (15th Edition)
(Temperature Conversions) Implement the following integer methods: Method celsius returns the Celsius equivalen...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
What populates the Smalltalk world?
Concepts Of Programming Languages
What are some ways to improve the efficiency of a planer? Do any of these apply to the shaper?
Degarmo's Materials And Processes In Manufacturing
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
- 2- The factorial n! of a positive integer n is defined as n! = 1*2*3 . .. * (n-1) * n Where 0! = 1 Write a function to calculate the factorial of a number. Argument: A number n of type unsigned int. Returns: The factorial n! of type long double. Write two versions of the function, where the factorial is • calculated using a loop calculated recursively Test both functions by outputting the factorials of the numbers 0 to 20.arrow_forwardDownload the file Ackermann.cpp. Inside the file the recursive Ackermann function is implemented (described in Chapter 14 Programming Challenge 9). Do the following and answer the three questions: a) Run the program. What happens?b) Now uncomment the code that is commented out and run the program again. What happens now?c) What do you think is going on?arrow_forwardConsider the following pseudo code, Method func() { PRINT “This is recursive function" func() } Method main( { func() } What will happen when the above snippet is executed?arrow_forward
- Hello, How can I store a whole book in a file in c language? I had some issues because the string is too long. here is the question: For this assignment I have uploaded a large text file that contains the entire book “Robinson Crusoe” byWilliam Defoe as file defoe-robinson-103.txt Consider the code shown below. It uses the fgets function.fgets is used to read (“get”) strings (“s”) from a file (“f”), hence the name “fgets”. It takes the following arguments:1. A pointer to an array large enough to store the string. In our case that is the char array calledbuffer of size MAX.2. The size of the array, in our case the symbolic constant MAX, set equal to 4000 in line 4.3. The file pointer of the file to read from, in our case bkPtr. Each call to fgets returns a string until the newline (“\n”) character or EOF is encountered. The codereads strings from the file defoe-robinson-103.txt in the while loop and prints them to screen.Implement this program and run it.arrow_forwardIn C Language Not Like This #include void histogram(int counter[][1]) { int i,j,k; printf("\nHistogram of alphabets in the given file\n"); for(k=97,i=0;iarrow_forwardHello, in C++ I need to solve this problem. *NOTE: The code must be able to read an input file, not individual user inputs of passwords. PROBLEM: Given a file of unsorted words with mixed case: read the entries in the file and sort those words into alphabetical order. The program should then prompt the user for an index, and display the word at that index. Since you must store the entire list in an array, you will need to know the length. The "List of 1000 Mixed Case Words" contains 1000 words. Note that some of these "words" have spaces, so read them one line at a time. You are guaranteed that the words in the array are unique, so you don't have to worry about the order of, say, "bat" and "Bat." For example, if the array contains ten words and the contents are cat Rat bat Mat SAT vat Hat pat TAT eat the sorted list is bat cat eat Hat Mat pat Rat SAT TAT vat and after sorting, the word at index 6 is Rat You are encouraged to use this data to test your program.arrow_forward
- Write a recursive function named largestDigit that accepts an integer parameter and returns the largest digit value that appears in that integer. Your function should work for both positive and negative numbers. If a number contains only a single digit, that digit's value is by definition the largest. You must not use any loops; you also cannot use the string type or any library functions. Your function must be recursive. Complete the following file: largestDigit.cpp 2 // You may use this helper function 3 int max(int a, int b) { return a < b ? b : a; } 4 5 int largestDigit(int n) if((n<0) && (n/10 if(n<0) n = 0)) return n; 8 -n; static int maxi 9 n%10; 0) return maxi; maxi = max(maxi, n%10); return largestDigit(n/10); = 10 if((n/10) 11 12 13 14 15 16 } Submit Calling with Arguments Name Arguments Actual Expected pass largestDigit 135725 7 7 pass largestDigit 111211 2 2 fail largestDigit 100000 1 pass largestDigit 4530021 5 pass largestDigit 7639852 fail largestDigit 76352 6 pass…arrow_forward/** numUnique returns the number of unique values in an array of doubles. * The array may be empty and it may contain duplicate values. * Unlike the previous questions, you can assume the array is sorted. * * Your solution should contain at most one loop. You may not use recursion. * Your solution must not call any other functions. * Here are some examples (using "==" informally): * * * * * Ⓒ == numUnique (new double[] { }) 1 == numUnique (new double[] {11}) 1 == numUnique (new double[] { 11, 11, 11, 11 }) 8 == numUnique (new double[] { 11, 11, 11, 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88, 88 }) 8 == numUnique (new double[] { 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88 }) * */ public static int numUnique (double[] list) { return StdRandom.uniform (100); //TODO: fix thisarrow_forwardX New Tab rn.edgenuity.com/player/ ples Semester A « def fib(n): Complete the code for this recursive function. if n == 1: return 0 if n == 2: ZA return 1 else: x + 1 2 3 4 # The first number in the list. # The second number in the list. Ⓒ # Add the previous two numbers. fib(n-1) + fib(n - 2) v6.2.1-0055.20221212.mainline O M 31 0 DELL A 2014arrow_forward
- This assignment will give you practice on basic C programming. You will implement a few Cprogramsarrow_forwardIn python, rite a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file or the name of a directory. If the pathname refers to a file, its filepath is displayed, followed by its contents, like so: File name: file_path Lorem ipsum dolor sit amet, consectetur adipiscing elit... Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory, like so: Directory name: directory_path File name: file_path1 Lorem ipsum dolor sit amet... File name: file_path2 Lorem ipsum dolor sit amet... ... Test this function in a new program.arrow_forwardCodeW X b For func x C Solved X b Answer X https://codeworkou... CodeWorkout X270: Recursion Programming Exercise: Count Characters For function countChr() write the missing part of the recursive call. This function should return the number of times that the letter "A" appears in string "str". Recall that str.substring(a) will return the substring of str from position a to the end of str, while str.substring (a, b) will return the substring of str starting at position a and continuing to (but not including) the character at position b. Examples: countChr ("ctcoWCAt") -> 1 Your AnsSwer: 1 public int countChr(String str) { 2. if (str.length() return 0; } (0 4. { int count = 0; www. 5. 9. if (str.substring(0, 1).equals("A")) { count = 1 7. { 9. return count + > 1:10 AM 50°F Clear 12/4/2021 呼arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License