Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Java cloning code problem

Status
Not open for further replies.

ichi

Newbie level 1
Newbie level 1
Joined
Jul 17, 2005
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,289
can i kno w what's the problem with this code,,,

public class clone{

static int[][] cloneArray(int source[][]){

int[][] x;

for(i=0;i<source.length;i++) {
for(j=0;j<source.length;j++) {
int x[j]=source[j];
}

return x;

}

public static void main(String args[]) {

int source[][]={{1,2,3},{3,4,5},{5,6,7}};
int receiver[][];

receiver=cloneArray(source);

for(i=0;i<receiver.length;i++) {
for(j=0;j<receiver.length;j++) {
System.out.println(receiver[j]);
}
}
}
}


i can't use clone implementation i have to make my own algorithm,,, now what's the problem with these one??
 

Re: cloning problem

It's java language source? If it's java then that its correct version:
Code:
public class clone {

  static int[][] cloneArray(int source[][]) {

    int[][] x = new int[source.length][source[0].length];

    for (int i = 0; i < source.length; i++) {
      for (int j = 0; j < source[i].length; j++) {
        x[i][j] = source[i][j];
      }
    }

    return x;

  }

  public static void main(String args[]) {

    int source[][] = {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}};
    int receiver[][];

    receiver = cloneArray(source);

    for (int i = 0; i < receiver.length; i++) {
      for (int j = 0; j < receiver[i].length; j++) {
        System.out.println(receiver[i][j]);
      }
    }
  }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top