Ask Question
11 July, 04:57

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.

+5
Answers (1)
  1. 11 July, 05:45
    0
    Public int add2n (int n)

    {

    int total;

    if (n % 2 = = 0)

    total = n--;

    while (n > 0)

    {

    total + = n;

    n - = 2;

    }

    return (total);

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers