Guest User

Untitled

a guest
Feb 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.util.*;
  2. public class test {
  3. public static void printArray(int[] a, int size) {
  4. if (size < 0)
  5. {
  6. System.out.println("Error");
  7. System.exit(0);
  8. }
  9. else if (size == 0)
  10. {
  11. System.out.println("1");
  12. }
  13. else if (size == 1)
  14. {
  15. System.out.println(a[size - 1]);
  16. }
  17. else
  18. {
  19. System.out.println(a[size - 1]);
  20. printArray(a, size - 1);
  21. }
  22. }
  23.  
  24. public static void main(String[] args)
  25. {
  26. int a[] = {2, 4, 1, 6};
  27. int size = a.length;
  28. System.out.println (printArray(a, size-1)); //void type not allowed here
  29.  
  30. }
  31. }
Add Comment
Please, Sign In to add comment