Java - Loop an array backward

Description

Loop an array backward

Demo

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        input.useDelimiter("\n");
        int cases = input.nextInt();
        String[] numbers = input.next().split(" ");
        input.close();/*from   ww w  .j  av a  2 s .  c  o  m*/

        for (int i = (numbers.length - 1); i > 0; i--) {
            System.out.print(numbers[i]);
            System.out.print(" ");
        }

        System.out.println(numbers[0]);

    }
}

Related Topic