Ask Question
4 February, 21:55

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.

+4
Answers (1)
  1. 4 February, 22:37
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers