waltermilner

Untitled

Mar 14th, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. public class Test {
  2.  
  3.   public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
  4.     int count = 0;
  5.     for (T e : anArray) {
  6.       if (e.compareTo(elem) > 0) {
  7.         ++count;
  8.       }
  9.     }
  10.     return count;
  11.   }
  12.    //////////
  13.  
  14.   public static void main(String args[]) throws Exception {
  15.     Integer[] arr = new Integer[3];
  16.     arr[0] = 5;
  17.     arr[1] = 7;
  18.     arr[2] = 9;
  19.     Integer elem = 6;
  20.     System.out.println(" total is " + Test.countGreaterThan(arr, elem));
  21.  
  22.   }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment