Advertisement
sfrsnyz

Григорьев ЯП ЛАБА 6

May 5th, 2021
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. /////////// Main
  2. import java.util.Arrays;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Test test=new Test();
  7.         test.testInt((a)->{ //генерация массива заданной длины
  8.             int[] arr=new int[a];
  9.             for(int i=0;i<a;i++){
  10.                 arr[i]=(int)(Math.random()*20+1);
  11.             }
  12.             System.out.println("Полученный массив размерности "+a+":"+ Arrays.toString(arr));
  13.         });
  14.         test.testString((str -> {//преобразование исходной строки в массив и вывод на экран
  15.             String[] arr=str.split("");
  16.             System.out.println("Полученный массив: "+ Arrays.toString(arr));
  17.         }));
  18.         test.testInt((a)->{ //вывод всех чисел до заданного включительно
  19.             for(int i=0;i<=a;i++){
  20.                 if(i==a)
  21.                     System.out.println(i+".");
  22.                 else
  23.                     System.out.print(i+", ");
  24.             }
  25.         });
  26.     }
  27. }
  28.  
  29. /////////// Intable
  30. public interface Intable {
  31.     void test(int a);
  32. }
  33.  
  34. ///////// Stringable
  35. public interface Stringable {
  36.     void test(String str);
  37. }
  38.  
  39. /////////// Test
  40. import java.util.Scanner;
  41.  
  42. public class Test {
  43.     public void testInt(Intable intable){
  44.         Scanner scanner=new Scanner(System.in);
  45.         System.out.println("Введите число: ");
  46.         int value= scanner.nextInt();
  47.         intable.test(value);
  48.     }
  49.     public void testString(Stringable stringable){
  50.         Scanner scanner=new Scanner(System.in);
  51.         System.out.println("Введите строку: ");
  52.         String value= scanner.next();
  53.         stringable.test(value);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement