public class DotCom01{
int[] locationCells; int numOfHits = 0; public void setLocationCells(int[] locs) { locationCells = locs; } public String checkYourself(String stringGuess) { int guess = Integer.parseInt(stringGuess); String result = "miss"; for(int cell : locationCells) { if(guess == cell) { result = "hit"; numOfHits++; break; } } if(numOfHits == locationCells.length) { result = "kill"; } System.out.println(result); return result; }
讯享网
}//错误: 在类 Xuexi.DotCom 中找不到 main 方法, 请将 main 方法定义为:
// public static void main(String[] args)
// 否则 JavaFX 应用程序类必须扩展javafx.application.Application
//Head First JAVA 125-150页
package Xuexi;
import java.util.ArrayList;
public class DotCom02 {
讯享网private ArrayList<String> locationCells; public void setLocattionCells(ArrayList<String> loc) { locationCells = loc; } public String checkYourself(String userInput) { String result = "miss"; int index = locationCells.indexOf(userInput); if(index >= 0) { locationCells.remove(index); if(locationCells.isEmpty()) { result = "kill"; }else { result = "hit"; } } return result; }
}
//Head First JAVA 125-150页
//DotCom的最终版150页
package Xuexi;
import java.util.*;
public class DotCom03 {
private ArrayList<String> locationCells; private String name; public void setLocattionCells(ArrayList<String> loc) { locationCells = loc; } public void srtName(String n) { name = n; } public String checkYourself(String userInput) { String result = "miss"; int index = locationCells.indexOf(userInput); if(index >= 0) { locationCells.remove(index); if(locationCells.isEmpty()) { result = "kill"; System.out.println("Ouch! You sunk" + name + " :( "); }else { result = "hit"; } } return result; }
}//错误: 在类 Xuexi.DotCom03 中找不到 main 方法, 请将 main 方法定义为:
//public static void main(String[] args)
//否则 JavaFX 应用程序类必须扩展javafx.application.Application
请问怎么解决,为什么这本书中的代码会运行不了?

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/59350.html