Answer the question
In order to leave comments, you need to log in
How to return an array in reverse order?
Hello!
I have an array with Fibonacci numbers:
Random random = new Random();
int[] array = new int[random.nextInt(16)];
int x = 1;
int y = 0;
int z;
for (int i = 0; i < array.length; i++) {
z = x + y;
x = y;
y = z;
array[i] = y;
}
System.out.println("Исходный массив: " + Arrays.toString(array));
Answer the question
In order to leave comments, you need to log in
Good afternoon
https://www.softwaretestinghelp.com/reverse-an-arr...
public class Main
{
public static void main(String[] args) {
Integer[] intArray = {10,20,30,40,50,60,70,80,90};
//print array starting from first element
System.out.println("Original Array:");
for(int i=0;i<intArray.length;i++)
System.out.print(intArray[i] + " ");
System.out.println();
//print array starting from last element
System.out.println("Original Array printed in reverse order:");
for(int i=intArray.length-1;i>=0;i--)
System.out.print(intArray[i] + " ");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question