public static boolean appearsIn(int[] a, int n)that, given an array of integers a and an integer n, verifies whether n appears in a.
appearsIn({1,2,3}, 2)
should return
true
.
public static int occurrences(int[] a, int n)that, given an array of integers a and an integer n, returns the number of occurrences of n in a.
occurrences({1,2,3,2,4,2}, 2)
should
return 3
.
public static int[] negativesToZero(int[] a)that, given an array of integers a, returns a new array obtained from a by replacing each negative integer with 0.
negativesToZero({1,-2, 3, 4, -5})
,
should return the array {1, 0, 3, 4, 0}
.
public static void invert(int[] a)that, given an array of integers a, inverts the positions of its elements.
invert(a)
, where a
is a reference to the array {1, 2, 3, 4}
, should
modify the array in such a way that a
refers to
{4, 3, 2, 1}
.
public static boolean palindrome(int[] a)that, given an array of integers a, returns the boolean value
true
if the sequence of elements of a coincides with
the same sequence in inverse order, false
otherwise.Class Main
to test the methods above.