Nelo5317 Nelo5317
  • 28-09-2017
  • Computers and Technology
contestada

Write a short java method that takes an integer n and returns the sum of all the odd positive integers less than or equal to n.

Respuesta :

rsmith6559
rsmith6559 rsmith6559
  • 28-09-2017
public int add2n( int n )
{
    int total;
    if( n % 2 == 0 )
        total = n--;

    while( n > 0 )
    {
        total += n;
        n -= 2;
   }
   return( total );
}

Answer Link

Otras preguntas

What is/are responsible for creating variations in climate and weather at different latitudes?A. Nothing-climate and weather aren't different at different latit
Although the state's authority derives from the implicit threat of physical force, when the state resorts to physical coercion to enforce its will, its legitima
which inequality is equalivalent to |x-4|<9​
Please help! As quick as you possibly can!
Find the Area of the rhombus. Please need help
On a number line what is the difference between -3/7 and -2/3?
You are trying to dunk a basketball. You need to jump 2.5 feet. In the air to dunk the ball. The height that your feet are above the ground is given by the func
Two previously undeformed cylindrical specimens of an alloy are to be strain hardened by reducing their cross-sectional areas (while maintaining their circular
Please please help me
chem help 36 and 37 the word cut off on 37 is larger​