Java program to display the elements of an array in STRAIGHT and in REVERSE order

PROGRAM:

public class Main {

public static void main(String[] args) {
        int[] num ={1,2,3,4,5};
        System.out.println("REVERSE ORDER:"):

        for(int i=num.length-1;i>0;i--)
        {
            System.out.println(num[i]);
        }
        System.out.println("STRAIGHT ORDER:"):
for(int i=0;i<num.length;i++) { System.out.println(num[i]);}     
}
}
OUTPUT:
REVERSE ORDER:
5
4
3
2
1
STRAIGHT ORDER:
1
2
3
4
5

Comments

Popular posts from this blog

Python program to sum up the Salary when the Name and Age matches with subsequent rows.

Automation using selenium and python/java interview question to order a product in e commerce website.