0
how do u write a program of first 10 odd numbers using only loops
4 Antworten
+ 2
public class firstten{
public static void main(String args[]){
int b=0;
int c=0;
for(int i=1;i<=20;i++)
{
b++;
if(b%2==1){
if(c<10){
c++;
System.out.println(b);
}
}
}
}}
0
Initialize integer oddCounter with 0. Start loop with 1 until let's say until 100. If odd number found, print one and add 1 to oddCounter. If oddCounter is more than 10, break the loop.
0
for(int i = 0; i < 20; i += 2)
System.out.println(i);
0
for(int i = 1; i < 20; i += 2)
System.out.println(i);