Created
April 2, 2019 06:01
-
-
Save namthatman/e80b031773fa3a2945517fd5068ec212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.math.*; | |
import java.security.*; | |
import java.text.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.function.*; | |
import java.util.regex.*; | |
import java.util.stream.*; | |
import static java.util.stream.Collectors.joining; | |
import static java.util.stream.Collectors.toList; | |
public class Solution { | |
// Complete the oddNumbers function below. | |
static List<Integer> oddNumbers(int l, int r) { | |
List<Integer> output = new ArrayList<Integer>(); | |
if (l % 2 == 0) { | |
l = l + 1; | |
} | |
while (l <= r) { | |
output.add(l); | |
l = l + 2; | |
} | |
return output; | |
} | |
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 l = Integer.parseInt(bufferedReader.readLine().trim()); | |
int r = Integer.parseInt(bufferedReader.readLine().trim()); | |
List<Integer> res = oddNumbers(l, r); | |
bufferedWriter.write( | |
res.stream() | |
.map(Object::toString) | |
.collect(joining("\n")) | |
+ "\n" | |
); | |
bufferedReader.close(); | |
bufferedWriter.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given two integers, l and r, print all the odd numbers between l and r (l and r inclusive). | |
Complete the oddNumbers function in the editor below. It has 2 parameters: | |
1. An integer, l, denoting the left part of the range. | |
2. An integer, r, denoting the right part of the range. | |
The function must return an array of integers denoting the odd numbers between l and r. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job!