Reverse array Learn programming Java

Lesson:

Arrays, Structures and Strings


Exercise:

Reverse array 12


Objetive:

Create a java program to ask the user for 5 numbers, store them in an array and show them in reverse order.


Code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		int[] numbers = new int[5];

		for (int i = 0; i < 5; i++)
		{
			System.out.printf("Number %1$s =  ", i + 1);
			numbers[i] = Integer.parseInt(new Scanner(System.in).nextLine());
		}

		System.out.println();
		for (int i = 4; i >= 0; i--)
		{
			System.out.printf("%1$s ", numbers[i]);
		}
	}
}