|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
问题描述】已知公式如下图,利用方法重载编程求f(x,y,z)的值 ,在main方法中实现x,y,z值 的输入及结果的输出 。
【输入形式】-1 2 5
【输出形式】0
【样例输入】
【样例输出】
【样例说明】
【评分标准】
- public class FormulaCalculator {
- public int f(int x, int y) {
- return x + y;
- }
- public int f(int x, int y, int z) {
- return x + y - z;
- }
- public static void main(String[] args) {
- FormulaCalculator calculator = new FormulaCalculator();
- int x = Integer.parseInt(args[0]);
- int y = Integer.parseInt(args[1]);
- int z = Integer.parseInt(args[2]);
- int result = calculator.f(x, y, z);
- System.out.println(result);
- }
- }
复制代码
这段代码定义了一个名为FormulaCalculator的类,其中包含了两个重载的f方法,分别接受两个和三个参数。在main方法中,通过命令行参数获取x,y,z的值,并调用f方法计算结果,最后输出结果。
|
|