954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

why doesn't it overwrites the array

this program divides the array into 6 segments of two elements each.but with each iteration the new array is not overwritten and it keeps displaying the first two values of the array 'array'

class tryy
{
        public static void main(String args[])
    {
	double array[]={12.43,34.34,4.432,9.433,4.787,4.2987,57.93,4.279,8.379,83.472,8.9867,879.56};


         for(int i=0;i<array.length;i++)
	{
		for(int j=0;j<(int)(array.length/6);j=j+2)
		{
		double numbers[]=new double[2];
		System.arraycopy(array,j,numbers,0,2);
		for(int u=0;u<numbers.length;u++)
		{System.out.println(numbers[u]);}

}
}
}
}
anusha88
Light Poster
28 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Remove outer loop and repeat for(j=0...) loop six times.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

done..thanks

anusha88
Light Poster
28 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You