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

I cannot seem to get this right.Find an equation of the line that has a slope of -4 and a y intercept of 9. y=
what is query table?​
Suppose a jar contained 19 red marbles and 12 blue marbles if you reach in the jar and pull out 2 marbles at random at the same time find the probability that t
3-2/5x=-1/3x+3 please help
What are purposes of epic poetry
he was offended that his actions had been ______? 1- Misconstrued 2- Miscreant 3- Misappropriate 4- Misaligned 5- Misnomer?!
Can someone answer this questions for me? I'll give branliest <3 (please at least 3 sentences or more) 1. Where were the main contributions of the Shang dyn
the point t(4,-5) is translated 3 units up what are the coordinates of the resulting point​
If you have a mass of 72 kg, and eat 333 g of pizza for dinner, what percent pizza are you. (record your answer to the nearest hundredth)
Which of the following ratios of nucleotides is constant for DNA? a. A+ U = G+C b. A + G =T + C C. A + C = U + G d. A + T = G + C