Answers for "store reverse array in another array java"

1

Reverse an array without using another array in java

// Reverse an array without using another array in java
import java.util.Scanner;
public class ReverseWithoutArray 
{
      public static void main(String[] args) 
      {
         int number, temp, a;
         Scanner sc = new Scanner(System.in);
         System.out.print("Please enter number of elements in the array: ");
         number = sc.nextInt();
         int[] arrayNumbers = new int[number];
         System.out.println("Please enter " + number + " number elements.");
         for(a = 0; a < number; a++)
         {
             arrayNumbers[a] = sc.nextInt();
         }
         for(a = 0; a < number; a++, number--)
         {
             temp = arrayNumbers[a];
             arrayNumbers[a] = arrayNumbers[number - 1];
             arrayNumbers[number - 1] = temp;
         }
         System.out.println("Reverse of an array is : ");
         for(a = 0; a < arrayNumbers.length; a++)
         {
             System.out.println(arrayNumbers[a]);
         }
         sc.close();
      }
}
Posted by: Guest on February-19-2021

Code answers related to "store reverse array in another array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language