如何调用方法并打印其结果?
public class Test {
public static int main (String args[]){
System.out.println(total);
}
public int numbers (int a, int b){
int total;
total = a + b;
return = total;
}
}
答案 0 :(得分:0)
请改为尝试:
public class Test {
public static void main (String args[]){
System.out.println(numbers(1, 2));
}
public static int numbers(int a, int b){
int total;
total = a + b;
return total;
}
}
变量的范围限定在定义它们的方法或类中,因此总数为'变量只能在'数字中访问。方法
答案 1 :(得分:-2)
公共课测试{
public static void main (String args[]){
System.out.println(numbers(anumber,bnumber));
}
public static int numbers (int a, int b){
int total;
total = a + b;
return total;
}