THINK FIRST·CODE LATER

← All labs

Reverse an array and search in it

Problem

Write a class ArrayTools with two static methods:

public static void reverse(int[] a)      // reverses the array in place
public static int indexOf(int[] a, int value)   // position of value, or -1

The main method reads a count n, then n integers, then one value to search for. It prints the reversed array on one line after Reversed: , with the numbers separated by a space, and then the position of the value in the original array:

Reversed: 9 7 5 3
Found at: 2

Search in the original array before reversing it. Print Found at: -1 when the value is absent.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.