java 复数类的问题 急~~~~~~

来源:百度知道 编辑:UC知道 时间:2024/06/05 14:30:44
public class mycomplex {

private int real= 0; //实数部分
private int vir = 0; //虚数部分

public Test(int real,int vir){
this.real= real;
this.vir= vir;
}
这是我定义的一个复数类,现在我想在定义一个结构体struct mycomplex x[1024],t,z,ce; 现在我想实现结构体里的这些变量能有这样的形式:t.real=某值 t.vir=0; z.real=某值;z.vir=0;我知道java 里没有结构体,用类,但是类里面的变量t,z,ce能用这种形式表示么?不能的话怎么表示?
2楼那位大哥~~~~~,如果我要mycomplex t,z,x[100];这样声明数组不行吧,怎么样可以???

public class mycomplex {

private int real= 0; //实数部分
private int vir = 0; //虚数部分

public Test(int real,int vir){
this.real= real;
this.vir= vir;
}
//
你的java类实例化之后便可这样用的:mycomplex t,z;t.test(某值,某值);z.test(某值,某值);
//
如果你想这样用:mycomplex t,z;t.real=某值;t.vir=0; z.real=某值;z.vir=0;
那么类改成这样:
public class mycomplex {

public int real= 0; //实数部分
public int vir = 0; //虚数部分

public Test(int real,int vir){
this.real= real;
this.vir= vir;
}
///////////////////////
//////////////////////
哥们,java里声明当然不可mycomplex t,z,x[100];
这样实例化数组:mycomplex[] x=new mycomplex[100];