Загрузка данных
import java.util.ArrayList;
public class pr51 {
public static void main(String[] args){
ArrayList<Integer> nosik = new ArrayList<>();
nosik.add(5);
nosik.add(4);
nosik.add(3);
nosik.add(4);
nosik.add(5);
nosik.add(5);
nosik.add(2);
nosik.add(5);
nosik.add(4);
nosik.add(5);
System.out.print("исходные оценки ");
for (int i = 0; i < nosik.size(); i++){
System.out.print(nosik.get(i) + " ");
}
double avarage = 0;
for (int i = 0; i < nosik.size(); i++){
avarage += nosik.get(i);
}
avarage = avarage / nosik.size();
System.out.print("\nсреднее " + avarage);
for(int i = nosik.size() - 1; i >= 0; i--){
if (nosik.get(i) < 3){
nosik.remove(i);
}
}
System.out.print("\nпосле удаления низких оценок ");
for(int i = 0; i < nosik.size(); i++){
System.out.print(nosik.get(i) + " ");
}
nosik.add(5);
System.out.print("\nпосле добавления пяти ");
for(int i = 0; i < nosik.size(); i++){
System.out.print(nosik.get(i) + " ");
}
}
}
import java.util.ArrayList;
import java.util.HashSet;
public class pr52 {
public static void main(String[] args){
String text1 = "Java is great Java is fun I hate Java";
System.out.print("Вход " + text1);
String text = text1.toLowerCase();
String[] words = text.split("\\s+");
HashSet<String> uniqe = new HashSet<>();
for(String word : words){
uniqe.add(word);
}
System.out.print("\nуникальны слова ");
System.out.print(uniqe);
System.out.print("\nколво: ");
System.out.print(uniqe.size());
System.out.println("\nсодержит 'java'?");
if (uniqe.contains("java")){
System.out.print("да");
}
else {
System.out.print("нет");
}}
}
import java.util.HashMap;
public class pr53 {
public static void main(String[] args) {
String text1 = "bublik pepsi cola bublik";
String text = text1.toLowerCase();
String[] words = text.split("\\s+");
HashMap<String, Integer> count = new HashMap<>();
for (int i = 0; i < words.length; i++) {
String word = words[i];
if (count.containsKey(word)) {
count.put(word, count.get(word) + 1);
} else {
count.put(word, 1);
}
}
for (String word : count.keySet()) {
System.out.println(word + " = " + count.get(word));
}
String big = " ";
int bigCount = 0;
for (String word : count.keySet()) {
if (count.get(word) > bigCount) {
bigCount = count.get(word);
big = word;
}
}
System.out.println("cамое частое слово " + big + " (" + bigCount + " раза)");
}
}
import java.util.ArrayList;
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> A = new ArrayList<>();
A.add(1);
A.add(2);
A.add(3);
A.add(4);
ArrayList<Integer> b = new ArrayList<>();
b.add(3);
b.add(4);
b.add(5);
b.add(6);
HashSet<Integer> set = new HashSet<>();
set.addAll(A);
set.addAll(b);
ArrayList<Integer> result = new ArrayList<>(set);
System.out.println("резултат " + result);
}
}