Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class test {
- public static void printArray(int[] a, int size) {
- if (size < 0)
- {
- System.out.println("Error");
- System.exit(0);
- }
- else if (size == 0)
- {
- System.out.println("1");
- }
- else if (size == 1)
- {
- System.out.println(a[size - 1]);
- }
- else
- {
- System.out.println(a[size - 1]);
- printArray(a, size - 1);
- }
- }
- public static void main(String[] args)
- {
- int a[] = {2, 4, 1, 6};
- int size = a.length;
- System.out.println (printArray(a, size-1)); //void type not allowed here
- }
- }
Add Comment
Please, Sign In to add comment