打印局部变量的值

时间:2017-06-13 11:48:20

标签: java

UITableViewCell

我无法打印j值..

4 个答案:

答案 0 :(得分:1)

  

System.out.println("显示valule" + ex.age());

您希望以上行打印年龄,但不会因为您的年龄方法没有返回任何内容。

试试这个:

int age()// Now your age method will return an integer value
{   
        int j=11;// local variable which is created under method
        return j;
}

答案 1 :(得分:0)

您需要返回j,因此您的功能应如下所示:

int age()// age is method here
{   
        int j=11;
        return j; // return j
}

答案 2 :(得分:0)

您必须为变量

编写返回方法
public int getAge()
{
    return age;
}

然后使用ex.getAge()作为年龄

答案 3 :(得分:0)

sysout将打印在其中传递的任何值。方法age()不返回任何值。应该修改age()方法以使返回类型为int并返回变量j而不是仅设置值。您通常应该使用下面的getter和setter并调用set方法并使用get方法在sysout中进行打印。

void setAge() {
 j = 11;
}

int getAge() {
   return j;
}
相关问题