Write a method that returns the maximum of two integers that are passed in as ar
ID: 3655481 • Letter: W
Question
Write a method that returns the maximum of two integers that are passed in as arguments. The method would have the following header: public static int max(int num1, int num2) Write a complete method including the header that returns true if the incoming argument, a double, is positive. Write a method that returns a 2D array that is a perfect copy of an incoming 2D array. Remember, you don't know the array dimensions beforehand. The method head would be: public static int[][] copyArray(int[][] array) Write a method that would print the reverse of a string. The method header would be: public static void reverseString(String s)Explanation / Answer
public static void main(String[] args) { // max of 2 integers int answer1 = max(5, 10); // max of 2 doubles double answer2 = max(5.53, 234.234); // max of 3 doubles double answer3 = max(234.234, 346.2422, 0.43534); // output System.out.println(answer1); System.out.println(answer2); System.out.println(answer3); } // compute the max of 2 integers, returning the largest integer public static int max (int a, int b) { if (a > b) { return a; } else { return b; } } // compute the max of 2 doubles, returning the largest double public static double max (double a, double b) { if (a > b) { return a; } else { return b; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.