fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) {
  11. int count = countOdd(new Integer [] {5, 7, 3, 9, 0});
  12. System.out.println(count);
  13. count = countOdd(new Integer [] {2, 6, 4, 8, 1});
  14. System.out.println(count);
  15. count = countOdd2(5, 7, 10);
  16. System.out.println(count);
  17. count = countOdd2(8, 2, 7);
  18. System.out.println(count);
  19. count = countOdd(new Integer[][] {{1, 2}, {3, 4, 5}});//extra point only
  20. System.out.println(count);
  21. count = countOdd(new Integer[][] {{6, 2}, {3, 4, 0}});//extra point only
  22. System.out.println(count);
  23. }
  24. static <T> int countOdd2(T... arguments) {
  25. return countOdd(arguments);
  26. }
  27. public static <T> int countOdd(T[] a)
  28. {
  29. int count=0;
  30. if (a[0] instanceof Object[]) {
  31. for (T sub : a) count += countOdd((T[])sub);
  32. }
  33. else {
  34. for (T i: a) {
  35. count = ((int)i % 2 != 0) ? ++count : count;
  36. }
  37. }
  38. return count;
  39. }
  40. }
Success #stdin #stdout 0.08s 48812KB
stdin
Standard input is empty
stdout
4
1
2
1
3
1