Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me with this question [30 Questiont: Programming Fundamentals: Description: Consider a non empty array inintArt (intth that contains integers as its elements. Write
please help me with this question
[30 Questiont: Programming Fundamentals: Description: Consider a non empty array inintArt (intth that contains integers as its elements. Write a Java program that accepts the above InintArras input parameter and returns an outstrArr (Stringi) based on the below logic Consider the elements of the InintArt in the direction left to right and obtain all the pairs of elements elementi element2) farmed from left to right) For each pair identified, obtain the absolute value of the difference between element and element2 . Among the obtained absolute difference values, identify the minimum absolute value as minAbs Val and maximum absolute value as makabs Vol Concatenate the minAbsVal and makAbsValinto a string say outStr in the format: eminAbsVolmaxAbsVol and add this outstr as an element to the outstrArt Return the outStrArt Assumption: The InIntArr would contain at least two elements Notes: No need to validate the assumption Only the non-zero minAbsVaf and maxAbsol must be considered Absolute difference would be computed for the elements only in the direction left to right Example: InintArt: 12.1.4.7.2) outStrArr: (128) Explanation In the above example, the first pair of elements identified from left to right is (2-1). The absolute difference of this pair of elements is 3 . The next pair of elements identified is 12,4), the absolute difference of this pair of elements is 2 . For the subsequent pairs (27) and (2. 21.the absolute difference Values are 5 and respectively Similarly, for the remaining paits (-14).-1.7).(-1.21.14. 71. (4.2) and (7.2) the absolute difference values obtained are 5. 8. 3.3.2 and respectively Among all the obtained absolute difference values, the minimum value te minAbs Valis 2 and the maximum value iemaxAbs Valis 8 . Hence concatenate the minAbs Val and maxAbsat as outstr2:8 and add this curser to the outStrArr. Finally, the outStrArr would be (2:0) Sample inputs and Outputs: InintArt outstrAIT {3.6) (3:39) (11,0,3,1,3) 11:11") 12.-1,5, 1, 7, 4,3,1) 11:8") 20 File Edit Selection View Go Run Terminal Exam Help Reference Tester java Question Solution java x package progusingjavaparti; 1 3 //DO NOT MODIFY THE CODE PROVIDED TO YOU 6 public class Solution { public String[] maxmindiff(int() in IntArr) { string() outstrarr = new String[1]; CO 9 // Implement your logic here 10 11 12 return outstrarr; 13 ) 14 15 I File Edit Selection View Go Run Terminal Exam Help Reference Question Solution java package progusingjavapart1; Tester java x 2 m ei oo public class Tester { Run Debug public static void main(String[] args) { int(in IntArr = {2, -1, 4, 7, 2); solution obj = new Solution(); String[] outstrarr obj.maxmindiff(inIntArr); for (int index=0;indexcoutStrarr.length; index++) { if (outstrArr[index] = null) { System.out.println(outStrArr(index]); 9 18 12 13 } 33 Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started