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

Java Help print the even numbers 0 to 100. Write programs that print the same ou

ID: 3675377 • Letter: J

Question

Java Help

print the even numbers 0 to 100. Write programs that print the same output as that program, but do it in the following ways:

1. Using a for loop that increments the loop control variable by 2 each iteration

2. Using a for loop whose loop control variable goes from 0 to 50.

3. Using a for loop whose loop control variable goes from 100 down to 0.

4. Using an infinite for loop with no conditional expression and exiting the loop with a break statement.

5. Using a while loop.

6. Using a do-while loop.

Explanation / Answer

public class ListEvenNumbers {

  public static void main(String[] args) {

  //define limit

  int limit = 100;

  System.out.println("Printing Even numbers between 0 and " + limit);

  for(int i=0; i <= limit; i+=2){

  // if the number is divisible by 2 then it is even

  if( i % 2 == 0){

  System.out.print(i + " ");

  }

  }

  }

}

public class ListEvenNumbers {

  public static void main(String[] args) {

  //define limit

  int limit = 50;

  System.out.println("Printing Even numbers between 0 and " + limit);

  for(int i=0; i <= limit; i++){

  // if the number is divisible by 2 then it is even

  if( i % 2 == 0){

  System.out.print(i + " ");

  }

  }

  }

}

public class ListEvenNumbers {

  public static void main(String[] args) {

  //define limit

  int limit = 0;

  System.out.println("Printing Even numbers between 100 and " + limit);

  for(int i=100; i>=limit; i--){

  // if the number is divisible by 2 then it is even

  if( i % 2 == 0){

  System.out.print(i + " ");

  }

  }

  }

}

public class ListEvenNumbers {

  public static void main(String[] args) {

  //define limit

  int limit = 2;

  System.out.println("Printing Even numbers between 0 and " + limit);

  for(int i=0; i <= limit; i++){

  // if the number is divisible by 2 then it is even

  if( i % 2 == 0){

  System.out.print(i + " ");

  }

                          Limit++;

                          If(limit=100){

                         Break;

                     }

  }

  }

}

public class ListEvenNumbers {

  public static void main(String[] args) {

  //define limit

  int limit = 100;

int i=0;

  System.out.println("Printing Even numbers between 0 and " + limit);

                While(i<=limit) {

  

  // if the number is divisible by 2 then it is even

  if( i % 2 == 0){

  System.out.print(i + " ");

  }

                     i++;

  

  }

}

public class ListEvenNumbers {

  public static void main(String[] args) {

  //define limit

  int limit = 100;

  int i=0;

  System.out.println("Printing Even numbers between 0 and " + limit);

              

   do{

  // if the number is divisible by 2 then it is even

  if( i % 2 == 0){

  System.out.print(i + " ");

  }

                    i++;

  }while(i<=limit)

  }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote