Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
- int count = 0;
- for (T e : anArray) {
- if (e.compareTo(elem) > 0) {
- ++count;
- }
- }
- return count;
- }
- //////////
- public static void main(String args[]) throws Exception {
- Integer[] arr = new Integer[3];
- arr[0] = 5;
- arr[1] = 7;
- arr[2] = 9;
- Integer elem = 6;
- System.out.println(" total is " + Test.countGreaterThan(arr, elem));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment