LenoraFerns
LenoraFerns LenoraFerns
  • 30-06-2021
  • Computers and Technology
contestada

Write an algorithm to print even numbers from 1 to 100

Respuesta :

klekaelly
klekaelly klekaelly
  • 01-07-2021

Answer:

// Java solution

for ( int i = 0; i < 101; i++)

{

 if ( i % 2 == 0)

 {

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

 }

}

Using modulus, whatever number we are currently on in our loop is evaluated to see if it is even. Any number divided by 2 that is even will not have a remainder, hence ==0. So we just print the numbers that satisfy that condition and we have all evens.

Answer Link

Otras preguntas

please help i am desperate
who do you think to be more responsible for increasing of corruption in nepal​
Who created this piece of art? A. Raphael B. El Greco C. Parmigianino D. Jacopo da Pontormo
A 90% confidence interval for a population is found to be (0.62,0.68) what is the sample proportion
Question 25 of 25 What is meant by the term flow in fiction? A. The uninterrupted forward movement of the story B. The use of words that carry meaningful associ
How to differentiate between an oxymoron and a paradox
In same Fig. A-3, a force F, having a slope of 2 vertical 3 horizontal, produces a clockwise moment of 330 ft-lb about A and a counterclockwise moment of 420 ft
Select the statement that is contrapositive of the following statement
A plane flies a distance of 300km without stopping and takes 1½ hours, what is the average speed of the plane in km/hr​
Select the correct answer. Choose the CONJUNCTION. Dad fixed the steps, for they were dangerous. OA. steps OB. for O C. were