Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use different loops to print the odd/negative numbers 1 to 101. All programs wil

ID: 3862447 • Letter: U

Question

Use different loops to print the odd/negative numbers 1 to 101. All programs will print the same output in the same order A-F the difference between the programs will be in structure of the loop. Using a for loop that increments the loop control variable by 2 each iteration Using a for loop whose loop control variable goes from 0 to 50. Using a for loop whose loop control variable goes from 100 down to 0. Using an infinite for loop with no conditional expression and exiting the loop with a break statement. Using a while loop. Using a do-while loop. There should be 6 different Snipping photos. One photo for each program A-F. -1 -3 -5 -7... -101

Explanation / Answer

A)

for(int i=-1;i>=-101;i-=2)
   System.out.println(i);

______________________

B)

for(int i=0;i<=50;i++)
   System.out.println(-(i*2+1));      

______________________

C)

for(int i=100;i>=0;i-=2)
System.out.println(i-101);      

______________________
D)

       for (int i = 1;; i += 2)
           if (i > 101)
               break;
           else
               System.out.println(-i);

_______________________

E)

   int i=1;
       while(i<=101)
       {
           System.out.println(-i);
           i+=2;
       }

_____________________

F)

       int i=1;
       do
       {
           System.out.println(-i);
           i+=2;
       }while(i<=101);

________________

Output:

-1
-3
-5
-7
-9
-11
-13
-15
-17
-19
-21
-23
-25
-27
-29
-31
-33
-35
-37
-39
-41
-43
-45
-47
-49
-51
-53
-55
-57
-59
-61
-63
-65
-67
-69
-71
-73
-75
-77
-79
-81
-83
-85
-87
-89
-91
-93
-95
-97
-99
-101

__________Thank You