29149 views.
class PrintArray {
//To display array in sequential order.
public static void printMyArray(int[] data, int index) {
if (index != -1) {
printMyArray(data,index - 1);
System.out.println(data[index]);
}
}
//To display array in reverse order.
public static void printMyArrayReverse(int[] data, int index) {
if (index != -1) {
System.out.println(data[index]);
printMyArray(data,index - 1);
}
}
public static void main(String[] args) {
//data array has five numbers.
int[] data = {66,33,88,99,100};
//passing data array and last index to start.
//To print sequential order
System.out.println("Sequential Order");
printMyArray(data,data.length - 1);
//To print array in reverse order.
System.out.println("Reverse Order");
printMyArrayReverse(data,data.length - 1);
}
}