首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

关于方法的返回值解决办法

2012-03-23 
关于方法的返回值程序如下class TestStuff{public int takeTwo(int x, int y){//x 0 y 3int z x

关于方法的返回值
程序如下

class TestStuff
{
public int takeTwo(int x, int y)
{
//x = 0; y = 3;
int z = x > y ? x : y;
return z;
//System.out.println("Max is " + z);
}

public static void main(String[] args)
{

TestStuff t = new TestStuff();
t.takeTwo(12,3);
}
}

以上能运行,但没有值,当保留"System.out.println("Max is " + z);"这句时,提示此句是不可运行代码
我要怎样才行将Z的值显示出来呢?

[解决办法]

Java code
class TestStuff{public int takeTwo(int x, int y){//x = 0; y = 3;int z = x > y ? x : y;return z;//System.out.println("Max is " + z);}public static void main(String[] args){TestStuff t = new TestStuff();System.out.println(t.takeTwo(12,3));}}
[解决办法]
public int takeTwo(int x, int y)
{
//x = 0; y = 3;
int z = x > y ? x : y;
return z;
//System.out.println("Max is " + z);
}

System.out.println("Max is " + z); 这句话必须放到return前面去!!

热点排行