好吧,基本上,我正在尝试编写一个简单的程序。目的是它读取一个文件(该文件是一组数字,用401填充401表),然后将数据写入数组并将数组打印到控制台。这将在以后用于查找特定数字,所以我会编写代码来查找数组中的最高和最低数字等。我不知道怎么回事,但我还没有让程序正常工作。每次运行此程序时,我得到的确切错误如下。
线程“main”中的异常java.lang.NumberFormatException:对于输入字符串:“363.0 360.0 354.0 349.0 343.0 339.0 333.0 319.0 324.0 325.0 324.0 317.0 317.0 322.0 322.0 320.0 315.0 314.0 313.0 311.0 309.0 308.0 315.0 313.0 326.0 332.0 336.0 341.0 346.0 350.0 353.0 353.0 352.0 351.0 352.0 353.0 351.0 349.0 354.0 357.0 360.0 366.0 371.0 377.0 383.0 387.0 393.0 398.0 402.0 409.0 414.0 419.0 425.0 422.0 439.0 442.0 444.0 446.0 448.0 450.0 453.0 457.0 460.0 460.0 462.0 464.0 465.0 466.0 467.0 467.0 469.0 470.0 471.0 470.0 470.0 470.0 470.0 470.0 477.0 479.0 480.0 486.0 490.0 492.0 495.0 497.0 496.0 499.0 499.0 500.0 500.0 499.0 499.0 499.0 500.0 500.0 497.0 494.0 491.0 488.0 487.0 485.0 490.0 490.0 488.0 484.0 482.0 481.0 478.0 474.0 471.0 466.0 461.0 454.0 449.0 443.0 436.0 432.0 422.0 410.0 397.0 389.0 381.0 375.0 365.0 340.0 318.0 289.0 283.0 276.0 266.0 255.0 241.0 235.0 233.0 234.0 235.0 235.0 239.0 257.0 281.0 302.0 321.0 330.0 337.0 354.0 373.0 383.0 389.0 401.0 410.0 413.0 403.0 389.0 381.0 373.0 363.0 351.0 343.0 335.0 328.0 322.0 314.0 306.0 298.0 293.0 285.0 275.0 270.0 276.0 283.0 286.0 286.0 285.0 283.0 283.0 283.0 27.0.0对软盘组件版本2008浏览次数上的详细信息更新时间287.0 271.0 274.0 276.0 299.0 283.0 299.0 293.0 294.0 295.0 295.0 297.0 307.0 312.0 314.0 314.0 314.0 310.0 304.0 310.0 304.0 305.0 305.0 304.0 325.0 335.0 344.0 351.0 35.0.0 36.0.0 366.0 370.0 379.0 382.0 386.0 389.0 391.0 391.0 390.0 390.0 393.0 395.0 397.0 402.0 408.0 412.0 413.0 414.0 415.0 415.0 416.0 414.0 41.0.0 411.0 410.0 408.0 407.0 407.0 406.0 404.0 402.0 39.0.0 38.0.0 375.0 397.0 39.0.0 38.0.0 38.0.0对2007年4月387.0 397.0 2007.0版本2007年4月25日047.0 447.0 457.0 453.0 457.0 458.0 459.0 45.0.0 05.0.0纯度458.0 458.0 456.0 455.0 454.0 454.0 455.0 455.0 455.0 454.0 452.0 452.0 451.0 450.0 450.0 450.0 450.0 447.0 442.0 440.0 437.0 436.0 436。 0 437.0 437.0 437.0 436.0 434.0 429.0 427.0 425.0 422.0 412.0 410.0 415.0 415.0 414.0 413.0 413.0 414.0 411.0 410.0 409.0 408.0 406.0 406.0 404.0 402.0 400.0 398.0 395.0 395.0 384.0 389.0 387.0 385.0 384.0 389.0 37.0.0 37.0.0 367.0 367.0 365.0 362.0 350.0 304.0 340.0 340.0 334.0 331.0 331.0 330.0 327.0 323.0 322.0 319.0 316.0 315.0 310.0 297.0 289.0 280.0 274.0 274.0 282.0 301.0 320.0 328.0 344.0 352.0 351.0 350.0 346.0 341.0 338.0 333.0 329.0 323.0 318.0 312.0 308.0 304.0“ at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source) 在java.lang.Double.parseDouble(未知来源) 在MultiArray.main(MultiArray.java:19)
现在,这是我的程序的代码。
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException; //importing tools
public class MultiArray {
public static void main(String[] args)throws IOException {
//variables
int rows = 401;
int columns = 401;
String file = "dmt.asc";
double dmtData[][] = new double[rows][columns]; //array
BufferedReader Reader = new BufferedReader(new FileReader(file)); //read the file
//split the numbers and write to array
for(int i = 0; i < rows; i++){
String rowArray [] = Reader.readLine().split("\t");
for(int j = 0; j < columns; j++){
dmtData[i][j] = Double.parseDouble(rowArray[j]);
}
}
Reader.close(); //close the reader and the file
//print out the array
for(int i = 0; i < rows; i++){
for(int j = 0; j < columns; j++){
System.out.println(dmtData[i][j]);
}
}
//code here to find highest number
System.out.println("The highest peak in this area is: ");
//code here to find lowest number
System.out.println("The lowest dip in this area is: ");
}
}
感谢您的帮助,我保证一旦我理解了Java,我会尽力回答这里的问题:)
答案 0 :(得分:0)
如果您的rowArray[j]
返回了正确的可解析双值,那么您的代码应该没有任何问题。查看您的文件是否由 \ t (标签)分隔,而不是jus “”(空格)。
我尝试执行你的代码时检查了同样的错误,并检查了你所说的相同的异常。