Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

public class Recurse3 { public static String hanoi(int nDisks, int fromPeg, int toPeg) { int helpPeg; String Sol1, Sol2, MyStep, mySol; // Contains moves if

public class Recurse3 { public static String hanoi(int nDisks, int fromPeg, int toPeg) { int helpPeg; String Sol1, Sol2, MyStep, mySol; // Contains moves if ( nDisks == 1 ) { return fromPeg + " -> " + toPeg + " "; } else { helpPeg = 6 - fromPeg - toPeg; // Because fromPeg + helpPeg + toPeg = 6 Sol1 = hanoi(nDisks-1, fromPeg, helpPeg); MyStep = fromPeg + " -> " + toPeg + " "; Sol2 = hanoi(nDisks-1, helpPeg, toPeg); mySol = Sol1 + MyStep + Sol2; // + = String concatenation ! return mySol;; } }  

public static void main (String[] args) { int n = 3; String StepsToSolution; StepsToSolution = hanoi(n, 1, 3); System.out.println(StepsToSolution); } }

----------------------------------------------

can someone help me with this java script to MAYA MEL please

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions