java code to print odd number

Solutions on MaxInterview for java code to print odd number by the best coders in the world

showing results for - "java code to print odd number"
Shaina
21 Sep 2017
1class JavaExample {
2   public static void main(String args[]) {
3	int n = 100;
4	System.out.print("Odd Numbers from 1 to "+n+" are: ");
5	for (int i = 1; i <= n; i++) {
6	   if (i % 2 != 0) {
7		System.out.print(i + " ");
8	   }
9	}
10   }
11}