Page 1 of 1

public class Arrays { @SuppressWarnings("unchecked") public static T[] swap(int i, int j, T... values) {

Posted: Thu Jun 02, 2022 8:11 am
by answerhappygod
public class Arrays<T> {
@SuppressWarnings("unchecked")
public static <T> T[] swap(int i, int j, T...
values) {
T temp = values;
values = values[j];
values[j] = temp;
return values;
}

// Your min & max code goes here
}
// tester code
public class MinMaxTester {
public static void main( String[] args ) {
Integer[] dataIntegers = {5, 7, -3, 8,
9, -1};
Integer minInt =
Arrays.min(dataIntegers);
System.out.println(minInt); // answer
should be -3
Integer maxInt =
Arrays.max(dataIntegers);
System.out.println(maxInt); // answer
should be 9

String[] dataStrings = {"Hello", "SEA",
"students", "hawks"};
String minString =
Arrays.min(dataStrings);
System.out.println(minString); //
answer should be SEA
String maxString =
Arrays.max(dataStrings);
System.out.println(maxString);
}
}