Modify Listing 18.8, TowerOfHanoi.java, so that the program finds the number of moves needed to move n
Question:
Modify Listing 18.8, TowerOfHanoi.java, so that the program finds the number of moves needed to move n disks from tower A to tower B.
Listing
Transcribed Image Text:
1 import java.util.Scanner; 2 3 public class Tower0fHanoi { /** Main method */ public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner (System.in); System.out.print("Enter number of disks: "); int n - input.nextInt(); 10 11 12 13 14 15 // Find the solution recursively System.out.println("The moves are:"); moveDisks(n, 'A', 'B', 'C'); 16 /** The method for finding the solution to move n disks 17 from fromTower to toTower with auxTower */ 18 public static void moveDisks(int n, char fromTower, 19 20 21 22 23 24 25 26 char toTower, char auxTower) { if (n == 1) // Stopping condition System.out.printin("Move disk " + n + " from " fromTower + " to " + toTower); else { moveDisks(n - 1, fromTower, auxTower, toTower); System.out.println("Move disk " + n + " from fromTower + " to " + toTower); moveDisks(n - 1, auxTower, toTower, fromTower); 28 29 30 } n6700 90 Enter number of disks: 4 -Enter The moves are: Move disk 1 from A to C Move disk 2 from A to B Move disk 1 from C to B Move disk 3 from A to C Move disk 1 from B to A Move disk 2 from B to C Move disk 1 from A to C Move disk 4 from A to B Move disk 1 from C to B Move disk 2 from C to A Move disk 1 from B to A Move disk 3 from C to B Move disk 1 from A to C Move disk 2 from A to B Move disk 1 from C to B
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (5 reviews)
Output Enter number of disks4 The moves are Move disk 1 from A to C Move disk 2 from A to B Move dis...View the full answer
Answered By
Atuga Nichasius
I am a Highly skilled Online Tutor has a Bachelor’s Degree in Engineering as well as seven years of experience tutoring students in high school, bachelors and post graduate levels. I have a solid understanding of all learning styles as well as using asynchronous online platforms for tutoring needs. I individualise tutoring for students according to content tutoring needs assessments.
My strengths include good understanding of all teaching methods and learning styles and I am able to convey material to students in an easy to understand manner. I can also assists students with homework questions and test preparation strategies and I am able to help students in math, gre, business , and statistics
I consider myself to have excellent interpersonal and assessment skills with strong teaching presentation verbal and written communication
I love tutoring. I love doing it. I find it intrinsically satisfying to see the light come on in a student's eyes.
My first math lesson that I taught was when I was 5. My neighbor, still in diapers, kept skipping 4 when counting from 1 to 10. I worked with him until he could get all 10 numbers in a row, and match them up with his fingers.
My students drastically improve under my tutelage, generally seeing a two grade level improvement (F to C, C to A, for example), and all of them get a much clearer understanding!
I am committed to helping my students get the top grades no matter the cost. I will take extra hours with you, repeat myself a thousand times if I have to and guide you to the best of my ability until you understand the concept that I'm teaching you.
5.00+
2+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called. Listing 1 import java.util.Scanner; 2 3 public class ComputeFibonacci { 4 /** Main...
-
In Code Fragment 5.1, we perform an experiment to compare the length of a Python list to its underlying memory usage. Determining the sequence of array sizes requires a manual inspection of the...
-
Modify Listing 2.10, ComputeChange.java, to display the nonzero denominations only, using singular words for single units such as 1 dollar and 1 penny, and plural words for more than one unit such as...
-
Go out onto the Web and compare three shopping bots for a product you are interested in (e.g., www.mysimon.com, www.bottomdollar.com, www.shopzilla.com, www.shopping.com, or www.pricegrabber.com)....
-
Every competitive equilibrium allocation x* belongs to the core of the corresponding market game. 02 - Core
-
Find the products in Problems 2330. [-4 3] -2 1
-
Repeat the calculations of Example 9.5, but for a total solution normality of 0.5. Data From Example 9.5:- For the Cu 2+ /Na + exchange with a strong-acid resin, show how the fraction CuR2 in the...
-
ABC, process costing Parker Company produces mathematical and financial calculators and operas at capacity. Data related to the two products are presented here. Total manufacturing overhead costs...
-
5. What effect do each of the following have on the regular payment and the total interest paid on a mortgage? Change Effect on Regular Payments (up/down) Effect on Total Interest Paid (up/down)...
-
Using the information provided below, complete Arlington Building Supply's (ABS) 2014 Form 1065 and Schedule D. Also complete Jerry Johnson and Steve Stillwell's Schedule K-1. Form 4562 for...
-
Revise Listing 18.9 to develop a program that lets the user use the + and ? buttons to increase or decrease the current order by 1, as shown in Figure 18.12a. The initial order is 0. If the current...
-
Write a recursive method to return the number of uppercase letters in an array of characters. You need to define the following two methods. The second one is a recursive helper method. Write a test...
-
Suppose the people of a given country place a very high value on their economic independence and control over their economic destiny. However, suppose the leaders of that country wish to join the EU...
-
how does the global trade organization/agreement affect information technology in healthcare both negative and positive? Explain
-
show what happens to the investment demand curve if there is an increase in depreciation. Provide economic intuition for your result
-
Sam, the cost accountant for Lockers Unlimited, has gathered the following data regarding manufacturing costs: Variable manufacturing costs are driven by kilograms of raw materials used, at $15.10...
-
Q4. Based on the 1960-2005 period, if a Canadian company were to import from Brazil and must pay in Brazilian reins when the goods are delivered in 90 days, should the company get the currency...
-
You are thinking of building a factory. The plant will cost 100,000 and can be used for two years. The factory construction will increase your profits by 55000 at the end of the first year and by ...
-
Sven Co. uses both special journals and a general journal. On June 30, after all monthly postings had been completed, the Accounts Receivable control account in the general ledger had a debit balance...
-
We all experience emotions, but some people disguise their true feelings better than others. Do you think this is a helpful or harmful thing to do? Under what conditions do you think it would be most...
-
If we let n denote the size of set S, and m denote the size of set T, what would be the running time of the operation S.addAll(T), as implemented on page 446, if both sets were implemented as skip...
-
Give a description, in pseudocode, for implementing the retainAll method for the set ADT, using only the other fundamental methods of the set.
-
Give a description, in pseudocode, for implementing the removeAll method for the set ADT, using only the other fundamental methods of the set.
-
How does lean production facilitate effective communication and collaboration across departments?
-
2. The idiophones in gamelan ensembles occur in pairs. The longest bar on a particular gamelan pair has a fundamental frequency (pitch) of 100Hz. Call this gamelan A. (a) (3 points) What are two...
-
The authors of The Creation of Inequality make the point that the Ice Age had barely thawed when some of our ancestors began "surrendering bits of equality." And that process unfolds across 15,000...
Study smarter with the SolutionInn App