protected static int test1(int p1){
p1 = 2;
                  return p1; 
}
public static void main(String[] args){
int i=0;
i=test1(i);
System.out.println(i);
}

解决方案 »

  1.   

    nono
    我提这个问题是想解决函数的多返回值问题,楼上的写法我是知道的。
      

  2.   

    难道你是这个意思?class Test5 { public Test5() {
    int i = 5;
    String s = "String";
    StringBuffer b = new StringBuffer();
    i = method(i, b);
    s = b.toString();
    System.out.println("int:" + i + "\nString:" + s);
    } public int method(int i, StringBuffer s) {
    s.append("aaa");
    return 10;
    } public static void main(String[] args)  {
    new Test5();
    }}
      

  3.   

    最简单的就是使用数组了public class test {
    protected static void test1(int[] p1){
    p1[0] = 2;
    }
    public static void main(String[] args){
    int i[]={0};
    test1(i);
    System.out.println(i[0]);
    }}
      

  4.   

    多谢二位给的源码,经过试验都能达到我想要的效果,更以数组的方式为佳(任何数据类型都可如法炮制)。
    不过在java中没有通过为参数加上返回的标记的方式来实现吗?例如delphi中的var 或 out
    etc: procedure (var p1: integer); //delphi中
    如果没有我就结帖了。
    再次感谢