Untitled
unknown
plain_text
9 months ago
1.6 kB
3
Indexable
Never
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; class Result { /* * Complete the 'oddNumbers' function below. * * The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. INTEGER l * 2. INTEGER r */ public static List<Integer> oddNumbers(int l, int r) { List<Integer> oddNumbers = new ArrayList<Integer>(); for (int i=l; i<=r; i++) { if (i%2 != 0) { oddNumbers.add(i); } } return oddNumbers; } } 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 l = Integer.parseInt(bufferedReader.readLine().trim()); int r = Integer.parseInt(bufferedReader.readLine().trim()); List<Integer> result = Result.oddNumbers(l, r); bufferedWriter.write( result.stream() .map(Object::toString) .collect(joining("\n")) + "\n" ); bufferedReader.close(); bufferedWriter.close(); } }
Leave a Comment