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
Post a Comment