// 定义一个名为Computer的类,用于执行加法操作
class Computer {
// add方法接受两个整数参数x和y,并返回它们的和
int add(int x, int y) {
return x + y; // 返回x和y相加的结果
}
}
// 定义一个名为xuexi10的公共类,这是主类
public class xuexi10 {
// main方法是程序的入口点
public static void main(String args[]) {
// 创建Computer类的一个实例,用于执行加法
Computer com = new Computer();
// 定义两个整数m和n,分别赋值为100和200
int m = 100;
int n = 200;
// 使用com实例的add方法计算m和n的和,并将结果存储在result变量中
int result = com.add(m, n);
// 打印第一次加法运算的结果
System.out.println(result);
// 再次使用com实例的add方法计算一个更复杂的表达式的结果
result = com.add(120 + m, n * 10 + 8);
// 打印第二次加法运算的结果
System.out.println(result);
}
}