ZakenChannel

Untitled

Jun 6th, 2024
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         firstTask();
  8.         System.out.println("____________________");
  9.         secondTask();
  10.         System.out.println("____________________");
  11.         thirdTask();
  12.         System.out.println("____________________");
  13.         newThirdTask();
  14.     }
  15.  
  16.     public static void firstTask() {
  17.         int n = 10;
  18.         int[] arr = new int[n];
  19.         for (int i = 0; i < arr.length; i++) {
  20.             arr[i] = new Random().nextInt();
  21.         }
  22.  
  23.         System.out.println(Arrays.toString(arr));
  24.  
  25.         for (int i = 0; i < arr.length; i++) {
  26.             if (arr[i] < 0) {
  27.                 for (int j = i; j < arr.length - 1; j++) {
  28.                     arr[j] = arr[j + 1];
  29.                 }
  30.  
  31.  
  32.                 i--;
  33.                 arr = Arrays.copyOf(arr, arr.length - 1);
  34.             }
  35.         }
  36.  
  37.         System.out.println(Arrays.toString(arr));
  38.     }
  39.  
  40.     public static void secondTask() {
  41.         int n = 5, m = 5, sum = 0;
  42.         int[][] arr = new int[n][m];
  43.  
  44.         for (int i = 0; i < n; i++) {
  45.             for (int j = 0; j < m; j++) {
  46.                 arr[i][j] = new Random().nextInt(1000);
  47.             }
  48.         }
  49.  
  50.         for (int i = 0; i < n; i++) {
  51.             for (int j = 0; j < m; j++) {
  52.                 System.out.print(arr[i][j] + " ");
  53.             }
  54.             System.out.println();
  55.         }
  56.  
  57.         for (int i = 0; i < n; i++) {
  58.             sum += arr[i][i];
  59.         }
  60.  
  61.         System.out.println(sum);
  62.     }
  63.  
  64.     public static void thirdTask() {
  65.         Scanner scanner = new Scanner(System.in);
  66.         String line = scanner.nextLine().toLowerCase();
  67.         String newLine = scanner.nextLine().toLowerCase();
  68.         int count = 0;
  69.  
  70.         char[] lines = line.toCharArray();
  71.         char[] newLines = newLine.toCharArray();
  72.  
  73.         if (lines.length == newLines.length){
  74.             for (char c : lines) {
  75.                 for (int j = 0; j < lines.length; j++) {
  76.                     if (c == newLines[j]) {
  77.                         count++;
  78.                         break;
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.  
  84.         if (count == lines.length) System.out.println("YES");
  85.         else System.out.println("NO");
  86.     }
  87.  
  88.     public static void newThirdTask(){
  89.         Scanner scanner = new Scanner(System.in);
  90.         String line = scanner.nextLine().toLowerCase();
  91.         String newLine = scanner.nextLine().toLowerCase();
  92.  
  93.         char[] firstLine = line.toCharArray();
  94.         char[] secondLine = newLine.toCharArray();
  95.  
  96.         Arrays.sort(firstLine);
  97.         Arrays.sort(secondLine);
  98.  
  99.         if (Arrays.equals(firstLine, secondLine)) System.out.println("YES");
  100.         else System.out.println("NO");
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment