Is there a general function or way in Java to calculate an equation of the form (a+b+…+n)^2 with a,b,n >= 0? [closed]What is an efficient way to implement a singleton pattern in Java?Is there a destructor for Java?Fastest way to determine if an integer's square root is an integerHow do I generate random integers within a specific range in Java?What's the simplest way to print a Java array?How to create a generic array in Java?How does C compute sin() and other math functions?Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missingJava tree data-structure?Ways to iterate over a list in Java
How do solar inverter systems easily add AC power sources together?
Is it true that different variants of the same model aircraft don't require pilot retraining?
Book featuring a child learning from a crowdsourced AI book
What is the sound/audio equivalent of "unsightly"?
What's the simplest way to calibrate a thermistor?
Is this password scheme legit?
Could the UK amend the European Withdrawal Act and revoke the Article 50 invocation?
Grep contents before a colon
Did anybody find out it was Anakin who blew up the command center?
Why did James Cameron decide to give Alita big eyes?
Time difference between banns and marriage
Notice period 60 days but I need to join in 45 days
Are there any to-scale diagrams of the TRAPPIST-1 system?
Is there a word or phrase that means "use other people's wifi or Internet service without consent"?
Talk interpreter
Are (c#) dictionaries an Anti Pattern?
How could a self contained organic body propel itself in space
What is Soda Fountain Etiquette?
How many petaflops does it take to land on the moon? What does Artemis need with an Aitken?
Did ancient peoples ever hide their treasure behind puzzles?
Is the internet in Madagascar faster than in UK?
If I said I had $100 when asked, but I actually had $200, would I be lying by omission?
Is a memoized pure function itself considered pure?
What's the point of fighting monsters in Zelda BoTW?
Is there a general function or way in Java to calculate an equation of the form (a+b+…+n)^2 with a,b,n >= 0? [closed]
What is an efficient way to implement a singleton pattern in Java?Is there a destructor for Java?Fastest way to determine if an integer's square root is an integerHow do I generate random integers within a specific range in Java?What's the simplest way to print a Java array?How to create a generic array in Java?How does C compute sin() and other math functions?Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missingJava tree data-structure?Ways to iterate over a list in Java
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to find a way to implement an algorithm in Java that can calculate (a+b+...+n)^2 with a,b,n >= 0. The purpose is to use it afterwards in order to calculate Jain's Fairness index for my algorithm in networks. Is there any standard way to do that or any specific library for advanced math that i might have missed?
java math equation
closed as too broad by EJoshuaS, Max Vollmer, meowgoesthedog, thewaywewere, gdlmx Mar 28 at 5:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I need to find a way to implement an algorithm in Java that can calculate (a+b+...+n)^2 with a,b,n >= 0. The purpose is to use it afterwards in order to calculate Jain's Fairness index for my algorithm in networks. Is there any standard way to do that or any specific library for advanced math that i might have missed?
java math equation
closed as too broad by EJoshuaS, Max Vollmer, meowgoesthedog, thewaywewere, gdlmx Mar 28 at 5:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
what do you mean by ... ?
– battlmonstr
Mar 27 at 21:03
1
You mean likesum = a + b + … + n; return sum * sum
?
– Nico Schertler
Mar 27 at 21:14
1
Your question is unclear. Is the sequence (a, b, ..., n) an arithmetic progression (e.g. 5, 10, 15, 20). If so, it's important that you say so.
– Leo Aso
Mar 27 at 21:15
add a comment |
I need to find a way to implement an algorithm in Java that can calculate (a+b+...+n)^2 with a,b,n >= 0. The purpose is to use it afterwards in order to calculate Jain's Fairness index for my algorithm in networks. Is there any standard way to do that or any specific library for advanced math that i might have missed?
java math equation
I need to find a way to implement an algorithm in Java that can calculate (a+b+...+n)^2 with a,b,n >= 0. The purpose is to use it afterwards in order to calculate Jain's Fairness index for my algorithm in networks. Is there any standard way to do that or any specific library for advanced math that i might have missed?
java math equation
java math equation
asked Mar 27 at 20:42
Σωκράτης ΚαλαμόπουλοςΣωκράτης Καλαμόπουλος
21 bronze badge
21 bronze badge
closed as too broad by EJoshuaS, Max Vollmer, meowgoesthedog, thewaywewere, gdlmx Mar 28 at 5:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by EJoshuaS, Max Vollmer, meowgoesthedog, thewaywewere, gdlmx Mar 28 at 5:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by EJoshuaS, Max Vollmer, meowgoesthedog, thewaywewere, gdlmx Mar 28 at 5:49
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
what do you mean by ... ?
– battlmonstr
Mar 27 at 21:03
1
You mean likesum = a + b + … + n; return sum * sum
?
– Nico Schertler
Mar 27 at 21:14
1
Your question is unclear. Is the sequence (a, b, ..., n) an arithmetic progression (e.g. 5, 10, 15, 20). If so, it's important that you say so.
– Leo Aso
Mar 27 at 21:15
add a comment |
what do you mean by ... ?
– battlmonstr
Mar 27 at 21:03
1
You mean likesum = a + b + … + n; return sum * sum
?
– Nico Schertler
Mar 27 at 21:14
1
Your question is unclear. Is the sequence (a, b, ..., n) an arithmetic progression (e.g. 5, 10, 15, 20). If so, it's important that you say so.
– Leo Aso
Mar 27 at 21:15
what do you mean by ... ?
– battlmonstr
Mar 27 at 21:03
what do you mean by ... ?
– battlmonstr
Mar 27 at 21:03
1
1
You mean like
sum = a + b + … + n; return sum * sum
?– Nico Schertler
Mar 27 at 21:14
You mean like
sum = a + b + … + n; return sum * sum
?– Nico Schertler
Mar 27 at 21:14
1
1
Your question is unclear. Is the sequence (a, b, ..., n) an arithmetic progression (e.g. 5, 10, 15, 20). If so, it's important that you say so.
– Leo Aso
Mar 27 at 21:15
Your question is unclear. Is the sequence (a, b, ..., n) an arithmetic progression (e.g. 5, 10, 15, 20). If so, it's important that you say so.
– Leo Aso
Mar 27 at 21:15
add a comment |
2 Answers
2
active
oldest
votes
Just sum those n values in for loop and then multiply it by itself. Or am i missing something?
add a comment |
The number of possible problems you may encounter is infinite, so you should not be surprised if you often get into a situation where there is no method to help you. Let's suppose that you have an array of numbers, let's suppose it has double
elements and the name of the array is input
, then:
double sum = 0;
for (int index = 0; index < input.length; index++)
sum += input[index];
double result = Math.pow(sum, 2);
//output holds the result
If there is a possibility of overflow, then you will need to handle it. Also, you will need to handle the validation that your items are positive.
@meowgoesthedog Oups, I thought the op wants the latter, sorry. Please see my edit.
– Lajos Arpad
Mar 27 at 22:37
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just sum those n values in for loop and then multiply it by itself. Or am i missing something?
add a comment |
Just sum those n values in for loop and then multiply it by itself. Or am i missing something?
add a comment |
Just sum those n values in for loop and then multiply it by itself. Or am i missing something?
Just sum those n values in for loop and then multiply it by itself. Or am i missing something?
answered Mar 27 at 21:15
tomietomie
1018 bronze badges
1018 bronze badges
add a comment |
add a comment |
The number of possible problems you may encounter is infinite, so you should not be surprised if you often get into a situation where there is no method to help you. Let's suppose that you have an array of numbers, let's suppose it has double
elements and the name of the array is input
, then:
double sum = 0;
for (int index = 0; index < input.length; index++)
sum += input[index];
double result = Math.pow(sum, 2);
//output holds the result
If there is a possibility of overflow, then you will need to handle it. Also, you will need to handle the validation that your items are positive.
@meowgoesthedog Oups, I thought the op wants the latter, sorry. Please see my edit.
– Lajos Arpad
Mar 27 at 22:37
add a comment |
The number of possible problems you may encounter is infinite, so you should not be surprised if you often get into a situation where there is no method to help you. Let's suppose that you have an array of numbers, let's suppose it has double
elements and the name of the array is input
, then:
double sum = 0;
for (int index = 0; index < input.length; index++)
sum += input[index];
double result = Math.pow(sum, 2);
//output holds the result
If there is a possibility of overflow, then you will need to handle it. Also, you will need to handle the validation that your items are positive.
@meowgoesthedog Oups, I thought the op wants the latter, sorry. Please see my edit.
– Lajos Arpad
Mar 27 at 22:37
add a comment |
The number of possible problems you may encounter is infinite, so you should not be surprised if you often get into a situation where there is no method to help you. Let's suppose that you have an array of numbers, let's suppose it has double
elements and the name of the array is input
, then:
double sum = 0;
for (int index = 0; index < input.length; index++)
sum += input[index];
double result = Math.pow(sum, 2);
//output holds the result
If there is a possibility of overflow, then you will need to handle it. Also, you will need to handle the validation that your items are positive.
The number of possible problems you may encounter is infinite, so you should not be surprised if you often get into a situation where there is no method to help you. Let's suppose that you have an array of numbers, let's suppose it has double
elements and the name of the array is input
, then:
double sum = 0;
for (int index = 0; index < input.length; index++)
sum += input[index];
double result = Math.pow(sum, 2);
//output holds the result
If there is a possibility of overflow, then you will need to handle it. Also, you will need to handle the validation that your items are positive.
edited Mar 27 at 22:36
answered Mar 27 at 22:15
Lajos ArpadLajos Arpad
30.6k19 gold badges65 silver badges123 bronze badges
30.6k19 gold badges65 silver badges123 bronze badges
@meowgoesthedog Oups, I thought the op wants the latter, sorry. Please see my edit.
– Lajos Arpad
Mar 27 at 22:37
add a comment |
@meowgoesthedog Oups, I thought the op wants the latter, sorry. Please see my edit.
– Lajos Arpad
Mar 27 at 22:37
@meowgoesthedog Oups, I thought the op wants the latter, sorry. Please see my edit.
– Lajos Arpad
Mar 27 at 22:37
@meowgoesthedog Oups, I thought the op wants the latter, sorry. Please see my edit.
– Lajos Arpad
Mar 27 at 22:37
add a comment |
what do you mean by ... ?
– battlmonstr
Mar 27 at 21:03
1
You mean like
sum = a + b + … + n; return sum * sum
?– Nico Schertler
Mar 27 at 21:14
1
Your question is unclear. Is the sequence (a, b, ..., n) an arithmetic progression (e.g. 5, 10, 15, 20). If so, it's important that you say so.
– Leo Aso
Mar 27 at 21:15