This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes single dimension array to multi dimension Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "single dimension array to multi dimension" Watch "single dimension array to multi dimension" New topic
Author

single dimension array to multi dimension

vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
Hi,
I have the requirement in the project to store the single dimensional array value to multi dimensioinal array.
e.g.
I ve array of blocks(area)from which I want to split each block(area) into X,Y-co-ordinates and store it in 2 dimensional array.
int[i][j]=pix[i][];something like that.
So how can I achieve it.right now I m getting INCOMPATIBLE TYPE error.please it is urgent.


VAIBHAV <BR>SCJP
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Post your code so we can see what you are trying to do.
Also, I am going to move this to Java General as it doesn't specifically relate to the exam.
Bill
Greg Up
Greenhorn

Joined: Feb 15, 2001
Posts: 4
Not positive about the contents of your first array...
This would be much easier for us if you could post your code as mentioned above.
Pressing onward, the most predictable way to assign the contents of one array to a second array is simply setting up loops and making the assignments inside.
In the case of a two dimensional array, you would normally set up nested loops.
HTH,
-Greg
vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
Here is the code.
I wish to grab the pixels of an image(1 dimension)and save it in an array converting the image inot x,y coordinates and rotate that coordinates accordingly to rotate the image ultimately.
--------------------code------------------------------
import java.applet.*;
import java.awt.image.*;
import java.util.*;
public class rotate extends Applet
{
Dimension d;
Image img;
int r=1,j;
int x,y;
int w,h;
int pixels[][],pix[][];
public void init()
{
setBackground(Color.white);
d = getSize();
w = d.width;
h = d.height;
try
{
img = getImage(getDocumentBase(),getParameter("img"));


w = img.getWidth(null);
h = img.getHeight(null);

pixels = new int[w*h][];
pix = new int[w*h][];
PixelGrabber pg = new PixelGrabber(img,0,0,w,h,pixels,0,w);

pg.grabPixels();

}
catch(InterruptedException e)
{ };

for(int i=0;i<h;i++)>
{

for(j=0;j<w;j++)>
{
int p[i][j] =pixels[i][];
x=(int)i*Math.cos(3.14*90/180);
y=(int)j*Math.sin(3.14*90/180);
pix[x][y]=p[i][j];


}
img = createImage(new MemoryImageSource(w,h,pix,0,w));

}
public void update()
{}
public void paint(Graphics g)
{
g.drawImage(img,0,0,this);

}

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: single dimension array to multi dimension
 
Similar Threads
Array
Enhansed For Loop Please explain me
Array conversion Question from Dan's test
reassigning new references to previously defined array variables
about hashmap implementation of arraylist