# Reverse integer array program

Been tasked with the following question:

Write a method that accepts an integer array and returns a new array with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8] the output array is [8, 6, 4, 2]. Then call your method from the main method.

I have this so far:

```public static int [] reverse (int a[]){
for ( int i = 0 ; i < a.length/2 ; i++ ){
int temp = a[i] ;
a[i] =  a[a.length-i-1] ;
a[a.length-i-1] = temp ;

}
return a;
}

public static void main(String[] args) {
int a [] = {2,4,6,8};
```

December 7, 2012 at 11:48 AM

Here is an example of reversing an integer array.

```import java.util.*;
class ReverseArray{
public static int [] reverse (int a[]){
for ( int i = 0 ; i < a.length/2 ; i++ ){
int temp = a[i] ;
a[i] =  a[a.length-i-1] ;
a[a.length-i-1] = temp ;

}
return a;
}

public static void main(String[] args)
{
int a[]=new int[5];
Scanner input=new Scanner(System.in);
System.out.println("Enter five array elements: ");
for(int i=0;i<a.length;i++){
a[i]=input.nextInt();
}
int array[]=reverse(a);
System.out.println("Array In Reverse Order: ");
for(int i=0;i<array.length;i++){
System.out.println(array[i]);
}
}
}
```

Related Tutorials/Questions & Answers:
Reverse integer array program
Reverse integer array program  Been tasked with the following question: Write a method that accepts an integer array and returns a new array with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8
Java Reverse integer array
Java Reverse integer array In this tutorial, you will learn how to reverse integer array. Here, we have created a method to reverse an array which has been passed as a parameter and returns a new array with all the elements in reverse
String reverse program
String reverse program  write a java program for reverse string? if the string is "Hi welcome to hyderabad" the reverse string is "hyderabad... for help. You can split the String into String array using split method of String
program of array
program of array  write a program that initializes an array with ten random integers and then prints four lines of output,containing:every element at an even index,every even element,all elements in reverse order,and only
PHP Array Sort in Reverse Order
PHP Array Sort in Reverse Order  Hi, I have just started learning... the PHP Array Sort in Reverse Order. Please suggest any online reference or example... the Reference example of PHP Array Sort in Reverse Order. Thanks
JavaScript array reverse example
JavaScript array reverse example       JavaScript Array class have one method reverse() which will reverse the order of element into the array. This has a simple syntax
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
ARRAY REVERSE - Java Interview Questions
ARRAY REVERSE  Hi,I Have Array Like This int arr[]={1,3,4,6,7,9,6,4} I Want Print Reverse Order Like This 4,6,9,7,6,4,3,1 Using loops I Want Source Code Plz Help me?  Hi Friend, Try the following code: class
program in array
program in array  print("code sample");write a program that initializes an array with ten random integers and then prints four lines of output,containing:every element at an even index,every even element,all elements in reverse
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
quiz asked by my lecturer for array reverse....
quiz asked by my lecturer for array reverse....  consider a 2 dimensional array size m by n.Derive a function that can be used to reverse the elements of the array such that the last element of the array becomes the first
A Program To Reverse Words In String in Java
A Program To Reverse Words In String in Java  A Program To Reverse... Tell Me This Program.  Here is an example that reverse the words...;i++){ if(i==ch.length){ reverse(ch,index,i-1
PHP Array Reverse
Php array is reversed by the function array_reverse(). array_reverse.... PHP Array Reverse Example <?php     \$arr=array("car... are <br>";     \$arr1=array_reverse(\$arr);
PHP Array Reverse Sorting
PHP Array Sort in Reverse Order In PHP there are three functions are available...() is one of them, it sorts an array in reverse order, rsort() is just opposite sort... that this function will sort an array in reverse order and maintain index association like
quiz asked by my lecturer for array reverse....
quiz asked by my lecturer for array reverse....  consider a 2 dimensional array size m by n.Derive a function that can be used to reverse the elements of the array such that the last element of the array becomes the first
Reverse String Program in Java
Reverse String Program in Java We are going to describe about reverse string program in java. In this example reverses a string entered by the user. We...(String args[]) { String string, reverse = ""; Scanner
how to check and print the no of times an integer is repeated in an array
how to check and print the no of times an integer is repeated in an array  how to check and print the no of times an integer is repeated in an array??? suppose my input is 2 4 2 5 2 4 3 4 5 2 then my output should be 2-4
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
java program (integer/decimal) - Java Beginners
java program (integer/decimal)  Accept a number from the user as command line arguments. The number could be an integer or decimal value. ? Display the absolute value of the input number ? Display the rounded off value
array variable in a java program
array variable in a java program  How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
Two Dimensional array program
to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array...Two Dimensional array program  consider a two dimensional array
java program based on array
java program based on array  Create Student class with attributes... StudentDemo which will have main method. Declare array of Student object with size 10. Initialize all 10 elements of this array with new objects. Write logic which
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
Out of bounce exception in the string reverse program - Java Beginners
have any confuse then you can this program. i am sending reverse program code...Out of bounce exception in the string reverse program  In the given program below this is taken from ur site but when i am executing it.It is giving
Reverse
Reverse  How to reverse two digits in javaprogramming
Reverse
Reverse  How to reverse two digits in javaprogramming
program to implement array of objects
program to implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
reverse
reverse  program to read a string and print the reverse string   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.*; public class ReverseString{ public static void main(String[]args
Two Dimensional Array Program
a integer for array declaration Two dimensional array program. We are going... will learn how to display arrange form of two dimensional array program... Two Dimensional Array Program
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop...; program . In this session we will teach how to use of a two dimensional array. First of all we will define a class "Matrix". In this program we
java 2 d array program
java 2 d array program  write a program 2-d matrix addition through user's input?  Hi Friend, Try the following code: import java.util.*; class MatrixAddition{ public static void main(String[] args
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n... { public static int reverse(int num){ int n = num; int
Three Dimensional Array program
Three Dimensional Array program       This is a very simple Java program. In this program we... the multidimensional array we are going to make a matrix. Now in this program use
create and use an array variable in a java program
create and use an array variable in a java program  how do i write a program that will prompt the user for a list of 5 prices, once the user has entered all values , your program should compute and display the following: The sum
Two Dimensional Array Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop ... dimensional array program. Firstly, we have to define class "TwoDimensional ". We are going to make a integer for array declaration Two dimensional array
reverse arrays in java
reverse arrays in java  how do i write a program in array of size n*m where both n and m are greater than 20 such that the 1st element of an array becomes the last and vice verse
reverse arrays in java
reverse arrays in java  how do i make a code that can be used to reverse the elements of an array in two dimension such that the last element of an array becomes the first element of the array and the first element of an array
reverse two dimensional arrays in java
reverse two dimensional arrays in java  reverse array elements in two dimensional array such that the last element becomes the first
Array list java program - Java Interview Questions
Array list java program  Create an employee class with an employee id's,name & address. Store some objects of this class in an arraylist. When an employee id is given, display his name & address? Please provide the DETAIL java
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats values in reverse order . for example, the call of mirror function would transform
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats values in reverse order . for example, the call of mirror function would transform
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats values in reverse order . for example, the call of mirror function would transform
Array in java
++, PHP and any other programming languages. We can use array in program... Initialized an integer array of length 7 when First element is 10, Second element is 20...Array in java In following example we will discuss about Array in Java. Array
reverse the charstring
reverse the charstring  how to reverse any character of the string