REVERSE ARRAY

package com.cnc;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("HOW MANY ELEMENT YOU WANT?");
int n = sc.nextInt();
int[] element = new int[n];
for (int i = 0; i < n; i++) {
System.out.println("ENTER ARRAY ELEMENT " + (i + 1));
element[i] = sc.nextInt();
}
System.out.println("ORIGINAL ELEMENT ");
for (int i = 0; i < n; i++) {
System.out.print(element[i] + " ");
}

System.out.println("\n REVERSED ELEMENT ");
for (int i = n-1; i >=0; i--) {
System.out.print(element[i] + " ");
}

}

package com.cnc;
public class Main {

  public static void main(String[] args) {
int [ ] array = {0,1,2,3,4,5};
for(int i = 0;i< array.length;i++){
System.out.print(array[i]+" ");
}
System.out.println(" ");
for(int i = array.length-1; i>=0;i--){
System.out.print(array[i]+" ");
}
}
}

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

USER INPUT PRINT ORIGINAL,REVERSE ARRAY AND SORTED ARRAY