Answer the question
In order to leave comments, you need to log in
How to print odd numbers from 0 to 20 using FOR?
You need to write a program that prints odd numbers from 0 to 20 using only a for loop.
public class TestClass {
public static void main(String[] args) {
for (int i = 0; i < 20; i++) {
if (i % 2 == 0) {
System.out.println(i);
}
}
}
}
public class TestClass {
public static void main(String[] args) {
for(int i=0; i < 20; i++) {
if(i%2 == 0) {
continue;
}
System.out.println("Number=" + i);
}
}
}
Answer the question
In order to leave comments, you need to log in
Well, probably because odd is when the remainder of the division is not equal to zero.
Need to i % 2 == 0
replace it with thisi % 2 != 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question