int arr[]={5,2,8,3,9,12,12,22};
for(int i=0;i<8;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
for(int j =1;j<8;j++){
int key = arr[j];
The method takes a list of names. Returns a string of the form "1. Ivan, 3. Peter ...", only with names on odd indices, respectively.
public static String constructString1(List<String> nameList) {
return IntStream.range(0, nameList.size())
.boxed()
.map(x -> x * 2 + 1 + ". " + nameList.get(x))
.collect(Collectors.joining(", "));
- 1 Написать запрос, считающий суммарное количество имеющихся на сайте новостей и обзоров. В результате выполнения запроса должно получиться: SUM 7
use test_tmp;
select count(*) as sum
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
public class MyArrayList<T> extends ArrayList<T> {
@Override
protected void removeRange(int fromIndex, int toIndex) {
throw new UnsupportedOperationException("you cannot remove any objects in range");
- Найти сумму элементов массива
- Найти максимальный элемент, значение и индекс
- Найти минимальный элемент, значение и индекс
- Найти среднее значение элементов массива
- Посчитать количество элементов равных заданному
- Посчитать количество элементов равных нулю
- [Посчитать количество элементов больше нуля](https://gist.githu
Integer[] array = {4, 5, -6, 4, 5, 3, 4, 2, 4, 5, 7,-1,-12,0,-8};
List<Integer> numbers = new ArrayList<>(Arrays.asList(array));
Map<Integer, Integer> numMap = new TreeMap<>();
numbers.forEach(i->numMap.put(i, (numMap.get(i) != null) ? (numMap.get(i) + 1) : 1));
numMap.entrySet()
.stream()
.forEach((x) -> System.out.print(x.getKey() + "\t" + x.getValue() + "\n"));
At this moment I found 3 solutions:
- Thread.stop (Deprecated).
- Thread.interrupt().
- Volatile flag.
The thread is forcefully stopped after a given amount of time. The Thread.stop() method causes the thread to stop what it is doing and throw a ThreadDeath exception.
final class Runner implements Runnable {
private String name;
import java.awt.dnd.InvalidDnDOperationException;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Scanner;
public class Main {
private static final char ADD = '+';
private static final char SUB = '-';
NewerOlder