程序中遇到了String操作的问题,请大家帮忙

Flowing_air 2006-03-24 05:47:50
InputStreamReader stdin = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(stdin);

for(int y=0; y<3; y++){
for(int x=0; x<3; x++){
int a = 0;
int inputNo = 0;
String inputTile;
//tile = tiles[x+3*y];(这个可以忽略)
a = str.indexOf(' ');
if (a!=-1){
inputTile = str.substring(0,a).trim();
str = str.substring(a).trim();
}
else {
inputTile = str; }
try{
inputNo = Integer.parseInt(inputTile);
这里进行存储inputNo
} catch (NumberFormatException e) {
if (inputTile=="blank")
tile.Set(x, y, 3, 3);(这里也是在存储,也可以认为是用数字0来代替blank和其他数值村到一次)
else{
System.out.println("Invalid Input2");
System.exit(0);

这段程序,本意是用来读取“2 3 5 blank 1 4 6 8 7”这样的字符串。然后分别存到一个arry中。如果读到blank。则存为零。原程序要复杂一些。我在这里简化了
...全文
152 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
8612177 2006-03-26
  • 打赏
  • 举报
回复
一群菜鸟
String aaa = "2 3 5 blank 1 4 6 8 7";
aaa = aaa.replaceAll("blank","0");
String args[] = aaa.split(" ");
rightboy 2006-03-25
  • 打赏
  • 举报
回复
不须用这么复杂的方法!
oracle_chinayi 2006-03-24
  • 打赏
  • 举报
回复
String aaa = "2 3 5 blank 1 4 6 8 7";
String[] temArry = aaa.split(" ");
int[] arry = new int[temArry.length];
for(int i = 0;i<temArry.length;i++)
{
if(temArry[i].equals("blank"))
{
arry[i] = 0;
}
else
{
arry[i] = Integer.parseInt(temArry[i]);
}
}
Flowing_air 2006-03-24
  • 打赏
  • 举报
回复
再顶一下:)
yanxiazhiqiu 2006-03-24
  • 打赏
  • 举报
回复
嘿嘿,不懂!
Flowing_air 2006-03-24
  • 打赏
  • 举报
回复
自己顶一下:)
Flowing_air 2006-03-24
  • 打赏
  • 举报
回复
但是每次在运行的时候总是出现“Invalid Input2”.观察了一下后,发现是在读取字符串后,操作出现的问题,但是我怎么也找不出来。。。汗。。

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧