如何返回两个整数

Alp*_*pha 0 java integer return

在这个简单的程序中我不能返回2个整数值,你能帮帮我吗?我能怎么做 ?

public class Aritmetica 
{

public static int div(int x , int y)

  { 

    int q = 0 ;
    int r = x ; 
    while ( r >= y ) 
    {
      r = r - y ;  
      q = q + 1 ;  

    }
    return r && q; **// Here i want to return x and y**
 }

public static void main(String[ ] args)
 {

 if ( ( x <=0 ) & ( y > 0 ) )

  throw new IllegalArgumentException ( " X & Y must be >0  " ) ;

  int res4= div(x,y);

  System.out.println( " q and r : "+ res4) ; **// and here i want to display q and r** 

}

}
Run Code Online (Sandbox Code Playgroud)

aio*_*obe 5

创建结果类型:DivisionResult,如下所示:

class DivisionResult {
    public final int quotient;
    public final int remaineder;
    public DivisionResult(int quotient, int remainder) {
        this.quotient = quotient;
        this.remainder = remainder;
    }
}
Run Code Online (Sandbox Code Playgroud)

并做

    ...
    return new DivisionResult(q, r);
}
Run Code Online (Sandbox Code Playgroud)

并打印结果:

  DivisionResult res4= div(x,y);

  System.out.println("q and r: " + res4.quotient + ", " + res4.remainder);
Run Code Online (Sandbox Code Playgroud)