我对编程很陌生,而且仍然容易受到无知的错误的影响。我有一个类,应该以数组的形式保存参数数据库。各个参数将通过另一个类的编号调用。为什么我在Ksp;
和}
旁边收到错误消息。我已经把它弄乱了很久。
谢谢你的帮助。很抱歉有更大的代码段。错误是朝向开始和结束
public class PlanMat
{
double GPa = Constants.GPascals;
public int i ;
public int eos [ ];
public double rho0[ ];
public double c [ ];
public double nn [ ];
public double Ks0 [ ];
public double Ksp [ ];
i = new int [ 51 ];
eos = new int [ 51 ];
rho0 = new double [ 51 ];
c = new double [ 51 ];
nn = new double [ 51 ];
Ks0 = new double [ 51 ];
Ksp =new double [ 51 ];
i = 0;
eos [ 0 ] = 0;
rho0 [ 0 ] = 0;
c [ 0 ] = 0;
nn [ 0 ] = 0;
Ks0 [ 0 ] = 0;
Ksp [ 0 ] = 0;
}
答案 0 :(得分:1)
public int i ;
i = new int [51];
然后你应该声明我喜欢一个数组
public int[] i ;
在您执行某些行之后i = 0;
这意味着i
是一个变量
首先,如果i
是array
或variable
答案 1 :(得分:1)
有两个问题
我应该是一个数组
public int [] i
您无法初始化变量并分配您所做的值。使用构造函数来执行此操作。类似于以下内容
公共课PlanMat {
double GPa = Constants.GPascals;
public int[] i = new int[51];
public int eos[];
public double rho0[];
public double c[];
public double nn[];
public double Ks0[];
public double Ksp[];
public PlanMat() {
i = new int[51];
eos = new int[51];
rho0 = new double[51];
c = new double[51];
nn = new double[51];
Ks0 = new double[51];
Ksp = new double[51];
i[0] = 0;
eos[0] = 0;
rho0[0] = 0;
c[0] = 0;
nn[0] = 0;
Ks0[0] = 0;
Ksp[0] = 0;
}
}
N.B。您只能在类定义中声明变量。但你不能在那里分配值。
答案 2 :(得分:1)
试试这个
public class PlanMat
{
public int i[];
public int eos[];
public double rho0[];
public double c[];
public double nn[];
public double[] Ks0;
public double[] Ksp;
public void assign(){
i = new int [ 51 ];
eos = new int [ 51 ];
rho0 = new double [ 51 ];
c = new double [ 51 ];
nn = new double [ 51 ];
Ks0 = new double [ 51 ];
Ksp =new double [ 51 ];
}
public void add(){
i[0] = 0;
eos [ 0 ] = 0;
rho0 [ 0 ] = 0;
c [ 0 ] = 0;
nn [ 0 ] = 0;
Ks0 [ 0 ] = 0;
Ksp [ 0 ] = 0;
}
}
有2个变化 我是一个数组而且 2.根据您的要求添加两个功能