Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Odd - Even - Transform Problem works on an array of integers ( both positive, negative and zero ) , by taking in a value
OddEvenTransform Problem works on an array of integers both positive, negative and zero by taking in a value a whole number that specifies the number of times the transformation has to be applied.
On an array of integers, the transformation that needs to occur, n number of times:
Adds three to each odd integer.
Subtracts three from each even integer
Example: means, the array with integers has to undergo transformation times. So the result is
Function Description
Complete the function oddEven Transform
in the editor below.
oddEven Transform has the following
parameters:
arr: an array of integers transform:a an integer which specifies how many times to perform transformation
The function needs to return the array after the transformation is complete.
Constraints
None
Input Format For Custom Testing
Sample Case
Sample Input For Custom Testing
Sample Output
Explanation
Give java code and complete this
import java.io;
import java.util.;
import java.util.stream.;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result
Complete the 'oddEvenTransform' function below.
The function is expected to return an INTEGERARRAY.
The function accepts following parameters:
INTEGERARRAY arr
INTEGER transform
public static List oddEvenTransformList arr, int transform
public class Solution
public static void mainString args throws IOException
BufferedReader bufferedReader new BufferedReadernew InputStreamReaderSystemin;
BufferedWriter bufferedWriter new BufferedWriternew FileWriterSystemgetenvOUTPUTPATH";
int arrCount Integer.parseIntbufferedReaderreadLinetrim;
List arr IntStream.range arrCount
mapToObji
try
return bufferedReader.readLinereplaceAlls$;
catch IOException ex
throw new RuntimeExceptionex;
mapString::trim
mapInteger::parseInt
collecttoList;
int transform Integer.parseIntbufferedReaderreadLinetrim;
List result Result.oddEvenTransformarr transform;
bufferedWriter.write
result.stream
mapObject::toString
collectjoining
;
bufferedReader.close;
bufferedWriter.close;
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