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

1. The body of a do/while loop is guaranteed to execute at least once. 2. Write

ID: 672144 • Letter: 1

Question

1. The body of a do/while loop is guaranteed to execute at least once.

2.

Write a small, complete program that will compile and, when run, will output and count the number of even numbers between 1 and 27 using either a for or do/while looping structure. The output should look like this:

2 4 6 8 10 12 14 16 18 20 22 24 26
There are 13 even numbers.

Here is code you can use to get started by copying/pasting into the answer:

public class Evens {
public static void main ( String args[] ) {

// make sure to use a for or do/while loop for this solution

}
}

Explanation / Answer

public class Evens

{

Public static void main ( String [ ] args )

{

int i, count;

for ( i=1; i<= 27; i++)

{

do

{

count =count +1;

system.out.println(“ ”, +i);

}

while ( i % 2 == 0);

}                                                        // end of for loop

system.out.println (“Total count is:”, +count);

}                                                        // end of main function

}                                                        // end of class