Merge pull request #1363 from shellhub/master

format code
This commit is contained in:
Du Yuanchao 2020-07-30 14:20:52 +08:00 committed by GitHub
commit 2890797194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,17 +5,14 @@ import java.util.Scanner;
class TowerOfHanoi { class TowerOfHanoi {
public static void shift(int n, String startPole, String intermediatePole, String endPole) { public static void shift(int n, String startPole, String intermediatePole, String endPole) {
// if n becomes zero the program returns thus ending the loop. // if n becomes zero the program returns thus ending the loop.
if (n == 0) { if (n != 0) {
return;
}
// Shift function is called in recursion for swapping the n-1 disc from the startPole to the intermediatePole // Shift function is called in recursion for swapping the n-1 disc from the startPole to the intermediatePole
shift(n - 1, startPole, endPole, intermediatePole); shift(n - 1, startPole, endPole, intermediatePole);
System.out.println("%nMove \"" + n + "\" from " + startPole + " --> " + endPole); // Result Printing System.out.format("Move %d from %s to %s\n", n, startPole, endPole); // Result Printing
// Shift function is called in recursion for swapping the n-1 disc from the intermediatePole to the endPole // Shift function is called in recursion for swapping the n-1 disc from the intermediatePole to the endPole
shift(n - 1, intermediatePole, startPole, endPole); shift(n - 1, intermediatePole, startPole, endPole);
} }
}
public static void main(String[] args) { public static void main(String[] args) {
System.out.print("Enter number of discs on Pole 1: "); System.out.print("Enter number of discs on Pole 1: ");