Need help with java H/W. A-F will have the same outputs just have to use the dif
ID: 3862214 • Letter: N
Question
Need help with java H/W. A-F will have the same outputs just have to use the different methods A-F to get them. Please dont write code on paper.
Thanks
30 points) Task 2: 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. A. Using a for loop that increments the loop control variable by 2 each iteration B. Using a for loop whose loop control variable goes from 0 to 50 C. Using a for loop whose loop control variable goes from 100 down to 0. D. Using an infinite for loop with no conditional expression and exiting the loop with a break statement. E. Using a while loop. F. Using a do-while loop. There should be 6 different Snipping photos. One photo for each program A-F. 101Explanation / 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