将两个变量传递给一个方法以获得两个结果 [英] Passing two variables to one method to get two results

查看:84
本文介绍了将两个变量传递给一个方法以获得两个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将两个变量传递给一个方法,并让该方法给我带来两个独立的结果.

I am trying to pass two variables along to a method and have the method give me back two independent results.

int numX = 5;
int numY = 3;

System.out.println(displayTwiceTheNumber(numX, numY));

}
public static int displayTwiceTheNumber(int numX, int numY) {
    int numW, numZ;
    numW, numZ = 2 * (numX, numY);
    return numW numZ;        
}

Java认为在 numW,numZ = 2 *(numX,numY); 我正在尝试重新定义 numX numY .我该如何在最后一个块中加上两个变量并给出两个结果呢?

Java takes it that at numW, numZ = 2 * (numX, numY); that I am trying to redefine numX and numY. How do I phrase the last block to take two variables and give two results?

推荐答案

单个int函数一次只能返回1个int.如果要返回2个值,请考虑两次调用该函数或创建一个要使用的自定义对象.

A single int function can only return 1 int at a time. If you want to return 2 values, consider calling the function twice or creating a custom object to be used.

这篇关于将两个变量传递给一个方法以获得两个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆