import java.io.*;
import java.lang.*;
import java.util.*;
final class iarray {
private int[] arr;
private int size;
public iarray(){
arr = null;
size = 0;
}
//Инициализация массива заданной размерности;
arr = null;
arr = new int[new_size];
size = new_size;
}
//кол-во чего-то?
public int count(Comparable<Integer> cmp){
int n = 0;
for(int i = 0; i < size; ++i){
if(cmp.compareTo(arr[i]) == 1)
++n;
}
return n;
}
//выполнение для каждого элемента
public void each(Comparable<Integer> cmp){
for(int i = 0; i < size; ++i)
cmp.compareTo(arr[i]);
}
//Создание копии массива;
public int[] getCopy(){
int[] carr = null;
try {
carr = new int[size];
return null;
}
System.
arraycopy(arr,
0, carr,
0, size
); return carr;
}
//Сортировка массива;
public void sort(){
if(arr != null)
}
//Заполнение из консоли массива целыми числами;
Scanner scan = new Scanner(_in);
clear();
if((size = scan.nextInt()) > 0){
arr = new int[size];
for(int i = 0; (i < size) && scan.hasNextInt(); ++i)
arr[i] = scan.nextInt();
}
scan = null;
}
//удаление
public void clear() {
arr = null;
size = 0;
}
//присвоить
public void set(int index, int val){ arr[index] = val; }
//получить
public int get(int index){ return arr[index]; }
//кол-во
public int getSize(){ return size; }
}
//Количество отрицательных элементов;
final class Negative implements Comparable<Integer>{
return (n < 0) ? 1 : 0;
}
}
//Количество четных элементов
final class Even implements Comparable<Integer>{
return ((n % 2) == 0) ? 1 : 0;
}
}
//Количество элементов, лежащих в диапазоне [a;b], а и b задаются пользователем
final class BetweenAB implements Comparable<Integer>{
public int a, b;
public BetweenAB(int _a, int _b) {
a = _a;
b = _b;
}
return (n >= a && n <= b) ? 1 : 0;
}
}
//Среднее значение
final class Avg implements Comparable<Integer>{
public double sum = 0.0d;
public int cnt = 0;
sum += n;
++cnt;
return 0;
}
public double getAvg() { return (cnt > 0) ? sum / cnt : 0.0d; }
}
//Сумма всех положительных элементов;
final class SumU implements Comparable<Integer>{
private int sum = 0;
if(n > 0)
sum += n;
return 0;
}
public int getSum(){ return sum; }
}
//Нахождение максимального и минимального значений;
final class MinMax implements Comparable<Integer>{
private int max, min;
public MinMax(int n){
max = min = n;
}
if(n > max)
max = n;
if(n < min)
min = n;
return 0;
}
public int getMin() { return min; }
public int getMax() { return max; }
}
class Cyberforum {
iarray arr = new iarray();
// ввод для примера из строки-потока устаревшего StringBufferInputStream
String s
= "15 1 2 3 4 -5 6 -7 -8 9 0 50 -12 15 17 -18"; arr.input_stream(rin);
rin = null;
/* ввод с консоли в начале размер массива далее элементы
System.out.print("Введите массив: ");
arr.input_stream(System.in);
*/
//мин/макс
MinMax mm = new MinMax(arr.get(0));
arr.each(mm);
System.
out.
printf("минимум: %d\nмаксимум: %d\n", mm.
getMin(), mm.
getMax()); mm = null;
//среднее значение
Avg avg = new Avg();
arr.each(avg);
System.
out.
println("среднее значение массива: " + avg.
getAvg()); avg = null;
//сумма положительных
SumU sum = new SumU();
arr.each(sum);
System.
out.
println("сумма положительных: " + sum.
getSum()); sum = null;
int a = 10, b = 20;
/* System.out.print("Введите диапазон [a;b]: ");
Scanner scan = new Scanner(System.in);
a = scan.nextInt();
b = scan.nextInt();*/
System.
out.
println("кол-во элементов в диапазоне [a;b]: " + arr.
count(new BetweenAB
(a, b
))); System.
out.
println("кол-во чётных: " + arr.
count(new Even
())); System.
out.
println("кол-во отрицательных: " + arr.
count(new Negative
()));
arr.sort();
for(int i = 0; i < arr.getSize(); ++i)
System.
out.
print(arr.
get(i
) + " "); }
}