URI Online Judge | 1067
Odd Numbers
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Read an integer value X (1 <= X <= 1000). Then print the odd numbers from 1 to X, each one in a line, including X if is the case.
Input
The input will be an integer value.
Output
Print all odd values between 1 and X, including X if is the case.
Input Sample | Output Sample |
8 | 1 3 5 7 |
URI Online Judge Solution 1067
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
int X;
Scanner input =new Scanner(System.in);
X = input.nextInt();
System.out.print(1+"\n");
for (int i = 1; i < X-1; i+=2) {
int oddNumber = i + 2;
System.out.print(oddNumber+"\n");
}
}
}
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks