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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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);
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply