Question: ava has an operator for computing the remainder when one integer is divided by another. This operator is indicated by %. If A and B

ava has an operator for computing the remainder when one integer is divided by another. This operator is indicated by %. If A and B are integers, then A % B represents the remainder when A is divided by B. (However, for negative operands, % is not quite the same as the usual mathematical modulus operator, since if one of A or B is negative, then the value of A % B will be negative.)

For example, 7 % 2 is 1, while 34577 % 100 is 77, and 50 % 8 is 2.

A common use of % is to test whether a given integer is even or odd: N is even if N % 2 is zero, and it is odd if N % 2 is 1. More generally, you can check whether an integer N is evenly divisible by an integer M by checking whether N % M is zero.

The following program segment loop is supposed to print the even integers from 2 to 100.

1. Using below program segment, write a program that asks the user to enter any number to find the number of even integers between 0 and that number (for example, the number of even integers between 0 and 10 is 4: 2, 4, 6, and 8)

2. Save and submit your work .

// Program # 3

counter = 0;

While (counter < 100) {

if (counter % 2 ==0 )

System.out.printf("%d ", counter);

counter +=1;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!