lr11 -> task_1 -> e2-4

This commit is contained in:
2026-04-07 21:06:51 +05:00
parent d114be3232
commit 1d32229ad9
3 changed files with 66 additions and 0 deletions

24
lr11/task_1/e2.java Normal file
View File

@@ -0,0 +1,24 @@
package lr11.task_1;
import java.util.Arrays;
public class e2 {
public static int[] getCommonElements(int[] nums1, int[] nums2) {
return Arrays.stream(nums1)
.filter(num -> Arrays.stream(nums2).anyMatch(n -> n == num))
.distinct()
.toArray();
}
public static void main(String[] args) {
int[] array1 = { 1, 2, 3, 4, 5 };
int[] array2 = { 3, 4, 5, 6, 7 };
int[] resultArray = getCommonElements(array1, array2);
System.out.print("Общие элементы: ");
for (int num : resultArray) {
System.out.print(num + " ");
}
}
}

21
lr11/task_1/e3.java Normal file
View File

@@ -0,0 +1,21 @@
package lr11.task_1;
import java.util.List;
import java.util.stream.Collectors;
public class e3 {
public static List<String> getCapitalizedStrings(List<String> strings) {
return strings.stream()
.filter(s -> Character.isUpperCase(s.charAt(0)))
.collect(Collectors.toList());
}
public static void main(String[] args) {
List<String> stringList = List.of("aaaAASd", "ASDASdsdasd", "qwedGSD", "SDFSD", "oiy", "SADjk", "Pyg");
List<String> result = getCapitalizedStrings(stringList);
System.out.println("Строки, начинающиеся с большой буквы:");
result.forEach(System.out::println);
}
}

21
lr11/task_1/e4.java Normal file
View File

@@ -0,0 +1,21 @@
package lr11.task_1;
import java.util.List;
import java.util.stream.Collectors;
public class e4 {
public static List<Integer> getSquares(List<Integer> numbers) {
return numbers.stream()
.map(n -> n * n)
.collect(Collectors.toList());
}
public static void main(String[] args) {
List<Integer> numbers = List.of(1, 2, 3, 4, 5, 10);
List<Integer> squares = getSquares(numbers);
System.out.println("Квадраты чисел:");
squares.forEach(System.out::println);
}
}