欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > Problem B: 构造方法

Problem B: 构造方法

2025/3/31 22:18:06 来源:https://blog.csdn.net/2303_76505072/article/details/146605366  浏览:    关键词:Problem B: 构造方法

1.题目问题

2.输入

3.输出

4.代码实现

class Number {private int x;private int y;// 构造方法public Number(int x, int y) {this.x = x;this.y = y;}// 加法方法public void add() {int result = x + y;System.out.println("the result is:" + result);}// 减法方法public void sub() {int result = x - y;System.out.println("the result is:" + result);}// 乘法方法public void mul() {int result = x * y;System.out.println("the result is:" + result);}// 除法方法public void div() {if (y != 0) {int result = x / y;System.out.println("the result is:" + result);} else {System.out.println("Error: Division by zero");}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词