fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. private static int max(int[] arr, int i) {
  12. // You should throw an exception if i is out of bounds...
  13.  
  14. if (0 == i) {
  15. return arr[0];
  16. }
  17. else {
  18. return Math.max(arr[i], max(arr, i - 1));
  19. }
  20. }
  21.  
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. int [] data = new int[10];
  25. Random rand = new Random();
  26. for (int i = 0; i < data.length; i++) {
  27. data[i] = rand.nextInt(1000);
  28. System.out.print(data[i] + " ");
  29. }
  30. System.out.println();
  31. System.out.println(max(data, data.length-1));
  32. }
  33. }
Success #stdin #stdout 0.08s 27824KB
stdin
Standard input is empty
stdout
402 861 44 3 275 677 358 524 311 138 
861