Wow. First, assignments are done with =, not ==, but the rest of that expression is completely baffling to me. Generally speaking it's best to do a job as simply as possible. In this case, that would be three for loops:

Once you get a little more comfortable, you can think about System.arraycopy() or something fancier. Now, as I say, I'm baffled by the expression you wrote out, so it's entirely possible that your assignment is calling for something more complex than just combining three arrays into one. Hopefully, this will get you started though.

Greg Charles wrote:Wow. First, assignments are done with =, not ==, but the rest of that expression is completely baffling to me. Generally speaking it's best to do a job as simply as possible. In this case, that would be three for loops:

Once you get a little more comfortable, you can think about System.arraycopy() or something fancier. Now, as I say, I'm baffled by the expression you wrote out, so it's entirely possible that your assignment is calling for something more complex than just combining three arrays into one. Hopefully, this will get you started though.

yes the assignement is very complex...........i donot know how i am able to complete.........i m theonly person who is gng to write the code for this...............

OK, deep breaths. You'll get through it. Representing formulas into code is actually one of the more straightforward things to do in programming. It's mainly a matter of knowing what the formula is and then getting the parentheses right. I'm not clear what you intend "output" to be here. Is it an array with n elements or a single value? Also, when you wrote "x" in your formula are you intending that to be a variable x, or multiplication? In any case, if you can state what you want to do in English, then it won't be that much harder to do it in Java.

there is requirement to do the summation.............

i want to do it shorter,to reduce the complexity.....
so i was searching for a alternative to replace the no of for loops in my code.

I found a method that is called as sum().
if,it can be implemented in my code...then the code become so easy .....
for summation Refernce to the function is given below

sum(expr, index, start, end) finds the partial sum using expr, with the index running from start to end.

it tried it but there is an error which says

the method sum is un defined for math class but it is mentioned in the link above

here is my code

import java.lang.Math.*;
public class sumation {
public static void main(String args[])
{
int n=10;
int y;
y=Math.sum(n^n/n,n,0,10); }

}

As there is so many For loops in my requirement so i want to reduce those loops and make the coding easier and simpler.....

if it is not possible please provide me an alternative for doing that.......

for example:-
If there is a series like "n / 2^(n +1)" for n=1 to 100....
is there any way to solve this using the direct fuction which is available in java.......

Ah, I see. Well, there are several reasons that doesn't work. First, the "sum" method is not part of Java's Math class. I looked at that link, and I'm not sure exactly what's it's documenting, but it's not the Java API. Google "javadoc Math" and you'll get better results.

Another problem is that certain operators they use in their example, like "^" for exponents and "!" for factorials, just don't work that way in Java.

Finally, passing an expression as an argument to a method is something called a closure, which is simply not supported in the Java language at the moment. You can approximate the idea though with an interface and an anonymous inner class. I would definitely suggest working out the functionality first with for-loops, then think about introducing a slick pseudo-closure into the mix.