Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my code down below import java.util.Scanner; public class HanoiTower { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); move(n,'a','b','c'); } public

This is my code down below import java.util.Scanner; public class HanoiTower { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); move(n,'a','b','c'); } public static void move(int n,char a,char b,char c){ if(n==1){ System.out.println("from " +a+"-->"+c); }else{ move(n-1,a,c,b); System.out.println("from " + a+"-->"+c); move(n-1,b,a,c); } } }

And this is the output

image text in transcribed

But I want to make the output like this with the numbers in front, so how do I do it. Thanks

1 :from a-->c 2 :from a-->b 3 :from c-->b 4 :from a-->c 5 :from b-->a 6 :from b-->c 7 :from a-->c

19 Hanoi Tower @Q untitled-1 Users 73641\/dea Projects untitled - untitled - ..src personalstuff Hanoi oweria - Intell) IDLA 2017.2.6 File Edit View Navigate Code Analyn Reistor Build Run Tools VCS Window Help untitled se personalstuff Hanoi Tower . ! Lojava Ways iostep.java Hancilowtrava untitled Curs 13611 des Projecte package personalstuff; idea cut import java.util.Scanner: SEL public class Hanoi Tower { chapter chapter2 5 bi personalstuff G ArrayListing Blahja public static void main(String args[]) CrackEvenodd 8 Gi 9 Scanner scanex Scanner(System.in); Utvide Factorial 10 int nesc.nextInt ); Gud 11 ve In, d'a', b: 'b', c'e'). Hana Tower 12 j HeloWordjes 13 Gjingina public static void nove(int n, cher 2, char b, char c) { Lalaa 14 if(n==1) LCHI 15 System out.println("from +c): Lal 16 }else Lover2 Noname moren-l,a, c,b); Occurence 18 System.out.println("Crou - 9+ --)-c) Odunum 19 over na n-1, h, 0, 0); GOnco @ Opepp Hur Towel mowo RunHanoitowe *C:\Program Files\Javaljdki. 8.0_151 bin java" ... II from a SC from &-->b from C-> from a--> from b--> from b c ? from &-> Process finished with exit code 0 IDE and Plugin Updates Intel IDEA is ready to update All fles are up-to-date moments ago) 121 CRLE UTRO

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

6.2 Explain the recruitment process.

Answered: 1 week ago