可以给我一些解释错塔为什么当我在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