There are 6 different programs + output required for this assignment. Please Hav
ID: 3886829 • Letter: T
Question
There are 6 different programs + output required for this assignment. Please Have 6 Different snipping photos with programs and outputs. Use loop structures below to print the even numbers 2 to 100. (2.4. 6.8.10. etc) Each program will have the same output. Write programs that print the same output as that program, but do it in the following ways: 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.Explanation / Answer
A)
public class EvenNumbers {
public static void main(String[] args) {
//Displaying the even numbers from 2 to 100
for (int i = 2; i < 100; i += 2) {
System.out.print(i + " ");
}
}
}
________________
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
______________________
B)
public class EvenNumbers {
public static void main(String[] args) {
//Displaying the even numbers from 2 to 200
for (int i = 2; i < 200; i += 2) {
System.out.print(i + " ");
}
}
}
____________________
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
_____________________
C)
public class EvenNumbers {
public static void main(String[] args) {
//Displaying the even numbers from 2 to 200
for (int i = 100; i > 0; i -= 2) {
System.out.print((102 - i) + " ");
}
}
}
____________________
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
_____________________
D)
public class EvenNumbers {
public static void main(String[] args) {
//Displaying the even numbers from 2 to 200
int i = 2;
for (;;) {
if (i <= 100) {
System.out.print(i + " ");
i += 2;
} else {
break;
}
}
}
}
____________________
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
____________________
E)
public class EvenNumbers {
public static void main(String[] args) {
//Displaying the even numbers from 2 to 200
int i = 2;
while (i <= 100) {
if (i % 2 == 0) {
System.out.print(i + " ");
}
i++;
}
}
}
__________________
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
__________________
F)
public class EvenNumbers {
public static void main(String[] args) {
//Displaying the even numbers from 2 to 200
int i = 2;
do {
if (i % 2 == 0) {
System.out.print(i + " ");
}
i++;
} while (i <= 100);
}
}
________________
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
_____________Could you rate me well.Plz .Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.