Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array of objects

Status
Not open for further replies.

chals1

Technical User
Sep 3, 2003
73
ES
I want an array of objects from a class named 'Complejo'but there's something wrong i cannot detect. Are those arrays, 'temp' and 'tempo', properly created?


public class Complejo {
private double a;
private double b;
private int k=0;
public Complejo[] raices(int n) {
Complejo[] temp = new Complejo[n];
Complejo[] tempo = new Complejo[n];
for(k=0; k<n-1; k++) {
temp[k] = new Complejo(Math.pow(a,1/n),(b+k*2*Math.PI)/n);
tempo[k] = new Complejo(temp[k].getParteReal(),temp[k].getParteImaginaria());
}
return tempo;

public String toString() {
return &quot;Resultado : &quot; + a +&quot; + &quot; + b + &quot; i &quot;;
}

}



class menu {
public static void main(String args[]) {
int n,k;
Complejo[] c4;
c4 = c1.raices(n);
for(k=0; k<n-1; k++)
System.out.println(c4[k].toString());
}
}
 
What error are you getting? Index out of bounds? Type mismatch? Why are you instantiating Complejo in its own method(s)?

************
RudeJohn
************
 
There aint errors when compiling.
Class Complejo and class menu are different java files.
 
Heh good catch, sean... thats why I asked if the error was an index out of bounds. :)

RJ

************
RudeJohn
************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top