public static void main(String[] args) {
try{
BufferedReader br=new BufferedReader(new FileReader("file.txt"));
String[] pole=br.readLine().split(" ");
double L=Double.parseDouble(pole[0]);
double N=Double.parseDouble(pole[1]);
String[] weight=new String[N];
double[] scale=new double[N];
double[] place=new double[N];
for(int i=0; i<N; i++){
weight[i]=br.readLine();
String[] variable=weight[i].split(" ");
double variable1=Double.parseDouble(variable[0]);
double variable2=Double.parseDouble(variable[1]);
scale[i]=variable2;
place[i]=variable1*variable2;
}
我有这个java代码。我想从文件中获取数字并将它们转换为 double,但它给了我错误:类型不匹配:无法从 double 转换为 int。我该如何解决这个问题?
最佳答案
因为 N 是 double
你需要一个类型大小写
String[] weight=new String[(int)N];
原因是 double
是浮点类型,您不能创建 length
1.5 的数组 :)
关于java - 类型不匹配 : can't convert from double to int java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20161139/