编写一个程序来解释文本文件中的一行.
想知道我是否应该将方法'parseWordData'中的局部变量命名scannedWord
为oppposed word
,因为word
它已经是一个类字段.
只要我宣布一个新变量而不是重新分配旧变量,一切都应该没问题......对吗?
public class WordData {
private String word;
private int index;
private LinkedList<Integer> list;
private boolean pathFound;
public WordData(String word, int index, LinkedList<Integer> list, boolean pathFound) {
this.word = word;
this.index = index;
this.list = list;
this.pathFound = pathFound;
}
public WordData parseWordData(String line){
Scanner scan = new Scanner(line);
int index = scan.nextInt();
String word = scan.next();
//precond and subGoal
LinkedList<Integer> list = new LinkedList<Integer>();
while(scan.hasNextInt()){
//add to LinkedList
}
return new …
Run Code Online (Sandbox Code Playgroud)