java.lang.numberformatexception问题

tmb3ates  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(338)

我有一个变量,它包含一些参数,这些参数会影响创建的weka模型。我想自动更改参数值。我得到了以下信息:

String c [] ={"1.0", "10.0", "20.0", "30.0", "40.0", "50.0", "60.0","70.0", "80.0", 
"90.0","100.0", "200.0", "300.0", "400.0","500.0", "600.0", "700.0", "800.0", "1000.0",
"2000.0"};
    System.out.println(c[1]);
    String opt  = ("-C "+c[0] +"-L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K 
      weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0 "); 

    String [] options = opt.split(" ");
    obj.train(new File(obj.str.get(2)), options);

我想在循环内自动改变c参数。然而,当我写下以下内容时:

String opt  = ("-C "+c[1] +"-L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0 ");

我收到一封信 java.lang.NumberFormatException :输入字符串。我该怎么做才能正常工作?错误在上面代码的最后一行。

9wbgstp7

9wbgstp71#

我试一下:

String c [] ={"1.0", "10.0", "20.0", "30.0", "40.0", "50.0", "60.0","70.0", "80.0", "90.0","100.0", "200.0", "300.0", "400.0","500.0", "600.0", "700.0", "800.0", "1000.0", "2000.0"};
for (i = 0; i < c.length; i++){
    String opt  = String.format("-C %S 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0 ",c[i]); 
}

我使用了string.format(“,…)函数并添加了%s作为占位符,c[i]的值将被放入其中。

相关问题