Ask 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.

+5
Answers (1)
  1. 29 December, 11:12
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers