import javax.swing.JOptionPane; public class StringHanoi { public static void main(String[] args) { String start = "One"; String finish = "Two"; String aux = "Aux"; String input = JOptionPane.showInputDialog("Enter the number of disks to move"); while( input != null ) { try { int n = Integer.parseInt(input); JOptionPane.showMessageDialog(null,moveDisks(n,start,finish,aux)); input = JOptionPane.showInputDialog("Enter the number of disks to move"); } catch(NumberFormatException e) { input = JOptionPane.showInputDialog("Input Error! Enter only digits."); } // end try/catch } // end while } // end main static String moveDisks(int n, String start, String finish, String aux) { String out = ""; if( n == 0 ) return out; out = moveDisks(n-1,start,aux,finish); out += "Move disk " + n + " from " + start + " to " + finish + "\n"; out += moveDisks(n-1,aux,finish,start); return out; } // end moveDisks } // end StringHanoi