return只能返回一个值,如果我有两个值都需要返回,除了定义数组,还有那些解决方法,大牛勿喷,请详细解答,谢谢!
例如:
public class CeShi
{
public int test(int a,int b)
{
return
} }
还有一个接口,红色字体标注的其实是实现接口的方法
例如:
public class CeShi
{
public int test(int a,int b)
{
return
} }
还有一个接口,红色字体标注的其实是实现接口的方法
所以这是不可能的
根据勾股定理:a2+b2=c2返回两个值得平方和,在外面再求出a,b
如何。哈哈,蛋疼的可以试试
Integer b=new Integer(1);public void test(Integer a,Integer b)
{
a=2;
b=3;
return;
}看看a,b是不是变了
{
return
}
这么来定义。。
用对象来定义,把两个值封装到一个对象中,也还是只能public Object test(int a,int b)
{
return
这么来定义。。你接收这个对象后,还是要解封的。。
java 语法规定了只能返回一个值或一个对象,貌似别的语言也不能这么返回多个值吧。已经定在那里的,没啥原因好讲。。
int r1 = r[0];
int r2 = r[1];Position p = findPosition(){};
int x = p.getX();
int y = p.getY();