可以給我一些解釋錯塔爲什麼當我在Android模擬器部署請告訴我河內
public class towers extends Activity {
/** Called when the activity is first created. */
private EditText text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (EditText) findViewById(R.id.editText1);
}
static int moves = 0;
static int totalDisks = 0;
public void myClickHandler(View view) throws java.io.IOException {
char fromPole = 'A';
char withPole = 'B';
char toPole = 'C';
switch (view.getId()) {
case R.id.editText1:
if (text.getText().length() == 0) {
Toast.makeText(this, "Please enter number of disks",
Toast.LENGTH_LONG).show();
return;
}
float disks = Float.parseFloat(text.getText().toString());
FileOutputStream fos = new FileOutputStream("TowersOfHanoiSolution.txt");
PrintStream ps = new PrintStream(fos);
solveHanoi(disks, fromPole, toPole, withPole, ps);
ps.close();
System.out.println();
text.setText("\nAmount of moves: " + moves + "\n");
}
}
static void solveHanoi(float disks, char start, char end, char intermediate, PrintStream ps) {
if (disks >= 1) {
solveHanoi(disks-1, start, intermediate, end, ps);
moveDisk(start, end, ps);
solveHanoi(disks-1, intermediate, end, start, ps);
}
}
static void moveDisk(char fromPole, char toPole, PrintStream ps) {
moves++;
if(totalDisks <= 10){
System.out.print("Move from " + fromPole + " to " + toPole + ". ");
ps.print("Move from " + fromPole + " to " + toPole + ". ");
if (moves%4 == 0){
System.out.println();
ps.println();
}
}
else {
ps.print("Move from " + fromPole + " to " + toPole + ". ");
if (moves%4 == 0){
ps.println();
}
}
}
}
如果你解釋了你期望發生的事情和未發生的事情,它將會很有用。 – 2011-05-06 19:48:24
首先,誰應該解決這個難題 - 用戶還是算法? – 2011-05-06 19:52:13
我是第二個@約翰說的,而且你也需要提供你的佈局,因爲代碼至多是我們需要幫助你的75%。僅查看代碼,您沒有爲editText1設置點擊處理程序,因此,在單擊editText1時看起來您想要執行某些操作,但實際上並未將點擊處理程序鏈接到該控件。 – RivieraKid 2011-05-06 20:10:21