【发布时间】:2016-03-14 22:55:43
【问题描述】:
我正在尝试替换“。”带有“X”。这最终适用于计算机将计算出的基于文本的迷宫。我只想改变第一个,希望我能从那里解决剩下的问题。这是我目前所拥有的。
Scanner sc = new Scanner(maze2);
public void traverseMaze(int row, int col, int handLocationX, int handLocationY) {
for(int rowCount = 0; rowCount <=11 ; rowCount ++){
row = rowCount;
for(int colCount = 0; colCount <= 11; colCount++){
col = colCount;
if(row ==2 && col ==0){
System.out.println(col);
System.out.println(row);
sc.next().replace(".", "X"); //stuck here HELP! :)
}
}
System.out.println(maze2);
}
【问题讨论】:
-
什么是sc?请解释你做了什么,有没有错误。
-
抱歉,sc 是扫描仪。没有错误。
-
如果 sc.next() 返回一个字符串,请注意 String.replace() 不会修改字符串本身,而是返回一个已替换出现的新字符串。跨度>
-
我会试一试,谢谢。