Advertisement
sfrsnyz

Юшкин ЯП 6

May 5th, 2021
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. //////////////// A
  2. import java.util.Scanner;
  3.  
  4. public class A {
  5. public void test(MyInterface inter){
  6.         Scanner scanner=new Scanner(System.in);
  7.         System.out.println("Введите 1 значение: ");
  8.         int a=scanner.nextInt();
  9.         System.out.println("Введите 2 значение: ");
  10.         int b=scanner.nextInt();
  11.         inter.testing(a,b);
  12.         }
  13. }
  14.  
  15. ////////////// MyInterface
  16. public interface MyInterface {
  17.     void testing(int a,int b);
  18. }
  19.  
  20. ////////// Main
  21. public class Main {
  22.     public static void main(String[] args) {
  23.         A a=new A();
  24.         a.test((b,c)->{ // лямбда выражение сложения
  25.             System.out.println(b+"+"+c+"="+(c+b));
  26.         });
  27.         a.test((b,c)->{ // лямбда выражение вычитания
  28.             System.out.println(b+"-"+c+"="+(b-c));
  29.         });
  30.         a.test((b,c)->{ // лямбда выражение умножения
  31.             System.out.println(b+"*"+c+"="+(c*b));
  32.         });
  33.     }
  34.  
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement