Java odd or even summing program questions

Asked 1 years ago, Updated 1 years ago, 394 views

Q. Write a method to find the sum of odd or even numbers from 1 to 100.

Conditions

It's easy to conditionalize the sum of odd and even numbers, but I don't know how to use Boolean parameters.. What should I do?

java

2023-04-13 10:37

1 Answers

I don't know Java, but in JavaScript...

if (user_wants_sum_of_odd_numbers_from_1_to_100) {
    // But wait a minute!!
    // If you just read the description of the problem, you have to find the sum of the order sequences, and the first term is fixed, the tolerance is fixed, and the length of the sequence is fixed.
    // If so, the sum of the sequences is always fixed and no other value can be obtained.
    // You can treat this as a constant and just hardcode it.
    return 2500;
} } else {
    // the same as above
    // Note: If you have to make a code that you pick from 1 to 100, one by one... https://greendreamtrre.tistory.com/59
    return 2550;
}


2023-04-13 14:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.