{"id":254,"date":"2005-12-13T08:00:00","date_gmt":"2005-12-13T08:00:00","guid":{"rendered":"https:\/\/out.cat\/?p=250"},"modified":"2005-12-13T08:00:00","modified_gmt":"2005-12-13T08:00:00","slug":"%e6%b2%b3%e5%86%85%e5%a1%94%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/out.cat\/?p=254","title":{"rendered":"\u6cb3\u5185\u5854\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"<p>import javax.swing.JOptionPane;<br \/>\npublic class TowersOfHanoi {<br \/>\n\/**<br \/>\n* @param args<br \/>\n*TowersOfHanoi.java :find solutions for the Towers of Hanoi problem<br \/>\n*by etc4.com<br \/>\n*\/<br \/>\npublic static void main(String[] args) {<br \/>\n\/\/ read number of disks ,n<br \/>\nString intString = JOptionPane.showInputDialog(null,&#8221;enter number of disks:&#8221;,<br \/>\n&#8220;TowersOfHanoi Input&#8221;,JOptionPane.QUESTION_MESSAGE);<br \/>\n\/\/covert string into integer<br \/>\nint n = Integer.parseInt(intString);<br \/>\n\/\/find the solutions recursively<br \/>\nSystem.out.println(&#8220;The moves are: &#8220;);<br \/>\nmoveDisks(n,&#8217;A&#8217;,&#8217;B&#8217;,&#8217;C&#8217;);<br \/>\nSystem.exit(0);<br \/>\n}<br \/>\n\/**the method for finding the solution to move n disks from fromTower to toTower<br \/>\n*with auxTower*\/<br \/>\npublic static void moveDisks(int n,char fromTower,char toTower,char auxTower){<br \/>\nif(n==1)\/\/stoping condition<br \/>\nSystem.out.println(&#8220;Move disk &#8220;+ n +&#8221; from &#8221; + fromTower + &#8221; to &#8221; + toTower);<br \/>\nelse{<br \/>\nmoveDisks(n-1,fromTower,auxTower,toTower);<br \/>\nSystem.out.println(&#8220;Move disk &#8220;+ n +&#8221; from &#8221; + fromTower + &#8221; to &#8221; + toTower);<br \/>\nmoveDisks(n-1,auxTower,toTower,fromTower);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import javax.swi&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[379,1384,512],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-2","tag-java","tag-1384","tag-512"],"_links":{"self":[{"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=254"}],"version-history":[{"count":0,"href":"https:\/\/out.cat\/index.php?rest_route=\/wp\/v2\/posts\/254\/revisions"}],"wp:attachment":[{"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/out.cat\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}