Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions