补全Java代码 package step7; import java.util.Scanner; interface Mycaculator{ int add(int a, int b); } public class LambdaTest { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); int b = scanner.nextInt(); //lambad表达式实现Mycaculator接口完成两数相加并打印输出结果使用lambda表达式实现Mycaculator接口,做到两数相加并打印输出结果。 测试说明 平台会对你编写的代码进行测试: 测试输入: 5 9 预期输出: 14
时间: 2023-06-02 14:07:41 浏览: 127
java代码-import java.util.Scanner;
5星 · 资源好评率100%
使用lambda表达式实现MyCalculator接口:
```
package step7;
import java.util.Scanner;
interface MyCalculator{
int add(int a, int b);
}
public class LambdaTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
MyCalculator calculator = (x, y) -> x + y;
int result = calculator.add(a, b);
System.out.println(result);
}
}
```
测试说明:
测试输入:5 9
预期输出:14
阅读全文