Topic: 求助!!请看下列代码

  Print this page

1.求助!!请看下列代码 Copy to clipboard
Posted by: zmzbs123
Posted on: 2005-11-11 09:25

public class Chess
{
public static int[][] point={{0,0,0,0,0},{0,0,0,0,0,},{0,0,0,0,0,}};
public void calculateBreath(int x,int y)
{
if(point[x][y]=0)
{}
}
}
调试的错误是类型不匹配,不能把整型转化为布尔型,我没有定义布尔型啊!!

2.Re:求助!!请看下列代码 [Re: zmzbs123] Copy to clipboard
Posted by: lfcjecboss
Posted on: 2005-11-11 09:51

if()语句 括号中]要求返回一个boolean型的 point[x][y]应是一个boolean型的植
例如
if(5>4)
system.out.println("fan hui de zhi shi "+(5>4));

输出将是:fan hui de zhi shi true

3.Re:求助!!请看下列代码 [Re: zmzbs123] Copy to clipboard
Posted by: lfcjecboss
Posted on: 2005-11-11 09:59

你把if(point[x][y]=0)-》if(point[x][y]==0)看看,应该可以编译

4.Re:求助!!请看下列代码 [Re: zmzbs123] Copy to clipboard
Posted by: wallacer
Posted on: 2005-11-11 11:34

if(point[x][y]=0) 是一个很常见的错误,原因是point[x][y]=0是一个赋值语句,不是一个bool表达式,所以应该是point[x][y]==0。在C++中为了避免错误一般这样写:if(0==point[x][y]),现在好像在java的编码规范里面也是这样规定的,推荐使用这种写法。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923