Question: Odd - Even - Transform Problem works on an array of integers ( both positive, negative and zero ) , by taking in a value

Odd-Even-Transform 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 (+3) to each odd integer.
Subtracts three (-3) from each even integer
Example: [3,4,9],3 means, the array with integers 3,4,9 has to undergo transformation 3 times. [3,4,9]=>[6,1,12]=>[3,4,9]=>[6,1,12] So the result is [6,1,12]
Function Description
Complete the function oddEven Transform
in the editor below.
oddEven Transform has the following
parameter(s):
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 0
Sample Input For Custom Testing
3
0
0
0
3
3
Sample Output
0
0
0
Explanation
[0,0,0]=>[-3,-3,-3]=>[0,0,0]=>[-3,-3,-3]
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 INTEGER_ARRAY.
* The function accepts following parameters:
*1. INTEGER_ARRAY arr
*2. INTEGER transform
*/
public static List oddEvenTransform(List arr, int transform){
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int arrCount = Integer.parseInt(bufferedReader.readLine().trim());
List arr = IntStream.range(0, arrCount)
.mapToObj(i ->{
try {
return bufferedReader.readLine().replaceAll("\\s+$","");
} catch (IOException ex){
throw new RuntimeException(ex);
}
})
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());
int transform = Integer.parseInt(bufferedReader.readLine().trim());
List result = Result.oddEvenTransform(arr, transform);
bufferedWriter.write(
result.stream()
.map(Object::toString)
.collect(joining("
"))
+"
"
);
bufferedReader.close();
bufferedWriter.close();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!