144k views
1 vote
Write a method printOdds1To11 that prints the odd numbers between 1 and 11 inclusive, one on each line. The program should calculate the odd numbers in a loop. The program text should not include the digits 3, 5, 7, or 9, but it will print these numbers out using System.out.println along with 1 and 11, in numerical order. It should only contain a single println statement. The program should take no arguments and return no value, just print things out.

User Uedemir
by
5.7k points

1 Answer

5 votes

Answer:

The method goes thus

static void printOdds1To11(){

for(int i = 1; i<=11;i++){

System.out.println(i);

}

}

Step-by-step explanation:

This line defines the method

static void printOdds1To11(){

This line iterates from 1 to 11 with an increment of 2

for(int i = 1; i<=11;i+=2){

This line prints the odd number in this range

System.out.println(i);

}

}

User Linus
by
5.3k points