PROBLEM 1 In a class named MidtermProblems, write a public static method named exchangeFirstWithLast that takes in a String s as an argument. The method will Return a modified String replacing the...

1 answer below »
Questions are attached.


PROBLEM 1 In a class named MidtermProblems, write a public static method named exchangeFirstWithLast that takes in a String s as an argument. The method will Return a modified String replacing the first with the last character, and the last character with the first character of the original string that was passed in. (Do not print out the String) Special cases: If s is null, the method should return null. If s is the blank string, “”, the method should return the blank string. Example: MidtermProblems.exchangeFirstWithLast(“tar”); Returns: “rat” PROBLEM 2 In a class named MidtermProblems, write a public static method named getDifferencePhrase that takes in 2 arguments, int a and int b. Calculate the difference and return a String as shown below. (Do not print out the String) If the absolute value of the difference is greater than or equal to 10, return “Big Difference of ” + diff. If the absolute value of the difference is less than 10, return “Single Digit Difference of ” + diff. If there is NO difference between the two numbers, return a + “ EQUALS ” + b Example: getDifferencePhrase(56, 89); String returned by method: “Big Difference of 33” Example: getDifferencePhrase(70, 64); String returned by method: “Single Digit Difference of 6” Example: getDifferencePhrase(43, 43); String returned by method: “43 EQUALS 43” PROBLEM 3 In a class named MidtermProblems, write a public static method named getSumOfEvens that takes in 1 argument int a, and returns the sum of all positive even numbers from 0 up to that number inclusive if it is also even. Remember if the argument is odd not to include it in the result. If the argument a is negative, return the negative number (Do not print the result) Example: getSumOfEvens(5); value returned by method: 6 Example: getSumOfEvens(6); value returned by method: 12 Example: getSumOfEvens(8); value returned by method: 20 Example: getSumOfEvens(9); value returned by method: 20 Example: getSumOfEvens(-5); value returned by method: -5 Example: getSumOfEvens(0); value returned by method: 0 Example: getSumOfEvens(1); value returned by method: 0 Example: getSumOfEvens(10); value returned by method: 30 Example: getSumOfEvens(11); value returned by method: 30 PROBLEM 4 Write a public static method name productAll that takes in 2 arguments int a, int b, and returns the product of all values between those two numbers inclusive. Remember a can be less than b, b might be less than a, or they may be equal. They can also be positive or negative. Example: productAll(2, 5); int returned by method: 120 Example: productAll(5, 2); int returned by method: 120 Example: productAll(3, 3); int returned by method: 9 Example: productAll(3, 5); int returned by method: 60 Example: productAll(-4, 3); int returned by method: 0 Example: productAll(-4, -2); int returned by method: -24 Example: productAll(-5, -2); int returned by method: 120 Example: productAll(-5, 2); int returned by method: 0 Example: productAll(-5, -3); int returned by method: -60
Answered 5 days AfterApr 06, 2021

Answer To: PROBLEM 1 In a class named MidtermProblems, write a public static method...

Kshitij answered on Apr 07 2021
141 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here