提问人:Jimmy 提问时间:11/17/2023 最后编辑:Jimmy 更新时间:11/17/2023 访问量:53
如何在 java 中将值从方法传递到方法 [已关闭]
How to pass value in java from methods to methods [closed]
问:
我是 java 新手,我想确认如何将值从方法传递给另一个方法/类。
在package1
public class class1
public void method1() {
a + a = e
}
在但不同package1
class file
public class class2
public void method2() {
b + b = f
}
在package2
public void method3() {
c + c = g
}
在package3
public void method4() {
// how can I get or use the value produce from method 1 , 2 and 3?
(e) + (f) + (g) = d
}
注意:我正在使用Eclipse作为IDE。
答:
1赞
Reilas
11/17/2023
#1
"...我想确认如何将值从方法传递到另一个方法/类。
有多种方法可以实现此目的。
我建议使用参数和返回值。
定义方法(Java 教程>学习 Java™ 语言>类和对象)。
class A {
static int f(int a) {
return a + a;
}
}
class B {
static int f(int b) {
return b + b;
}
}
class C {
static int f(int c) {
return c + c;
}
}
class D {
static int f() {
return A.f(1) + B.f(2) + C.f(3);
}
}
评论
return