Created
September 18, 2022 14:20
-
-
Save gmakc-094423/7e7516075a2f30771ae72f4204f546b8 to your computer and use it in GitHub Desktop.
Домашнее задание к семинару 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dz_03; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
public class dz_03_01 { | |
public static void main(String[] args) { | |
ArrayList<Integer> numList = new ArrayList<Integer>(); | |
Collections.addAll(numList, 1, 3, 6, 3, 8, 2, 5, 8, 77, 12, 76, 22, 2, 67); | |
System.out.printf("Исходный список: %s\n", numList); | |
ArrayList<Integer> sample = new ArrayList<Integer>(); | |
for (Integer i : numList) { | |
if (i % 2 == 0) { | |
Collections.addAll(sample, i); | |
} | |
} | |
numList.removeAll(sample); | |
System.out.printf("Обработанный список: %s\n", numList); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dz_03; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
public class dz_03_2 { | |
public static void main(String[] args) { | |
ArrayList<Integer> numList = new ArrayList<Integer>(); | |
Collections.addAll(numList, 3, 1, 6, 3, 8, 2, 5, 8, 77, 12, 76, 22, 2, 67); | |
System.out.printf("Исходный список: %s\n", numList); | |
Integer min = numList.get(0); | |
Integer max = min; | |
Integer midle = min; | |
for (Integer i : numList) { | |
if (min >= i) { | |
min = i; | |
} | |
if (max <= i) { | |
max = i; | |
} | |
if (min + (min + max) / 4 <= i && i < max - (min + max) / 4) { | |
midle = i; | |
} | |
} | |
System.out.printf("MIN: %s\nMAX: %s\nMIDLE: %s\n", min, max, midle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment