Answer the question
In order to leave comments, you need to log in
How to display the number of array elements greater than a given number?
the whole essence of the task, here:
Create class MyTestMethod with generic static method calcNum (with two parameters: an array T[] and variable maxElem of type T) that counts the number of elements in an array T[] that are greater than a specified element maxElem.
That is, how to search for the maximum number in the code, I understand:
double max = arra[0];
for (int i = 0; i < arra.length; i++) {
if (arra[i] > max)
max = arra[i];
}
System.out.println("Max is " + max);
public static <T> int calcNum(T[] array, T maxElem) {
int count = 0;
for (int i = 0; i < array.length; i++) {
for (int j = i; j < array.length; j++) {
System.out.println((array[i, j]);
}
}
Thank you for your attention
Answer the question
In order to leave comments, you need to log in
Here's what Google translate says about it:
Create a class MyTestMethod with a generic static method calcNum (with two parameters: an array T[] and a variable maxElem of type T) that counts the number of elements in the array T[] greater than the specified maxElem.
static <T extends Comparable<T>> int calcNum(T[] array, T maxElem) {
int count = 0;
// Тривиальная реализация подсчета количества элементов, больших чем maxElem.
return count;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question