2012-12-12 41 views
0

好吧,基本上,我想写一个简单的程序。其目的是读取一个文件(该文件是一组401个401表格),然后将数据写入数组并将数组打印到控制台。这将不再用于查找特定的数字,所以就像我将编写代码来查找数组中的最高和最低数字一样。我现在还不知道如何,但是我还没有完成该程序的工作。每次我运行这个程序,我得到的确切错误如下。异常在线程“主要”java.lang.NumberFormatException:对于输入字符串

异常在线程 “主” 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 320.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 350.0 346.0 339.0 338.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 432.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 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 2 66.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 279.0 274.0 270.0 264.0 255.0 245.0 239.0 238.0 238.0 239.0 240.0 249.0 256.0 262.0 268.0 272.0 275.0 276.0 275.0 273.0 271.0 269.0 269.0 271.0 274.0 276.0 279.0 283.0 289.0 293.0 294.0 295.0 295.0 297.0 307.0 312.0 314.0 314.0 314.0 313.0 312.0 310.0 307.0 305.0 304.0 303.0 304.0 299.0 291.0 308.0 325.0 335.0 344.0 351.0 358.0 361.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 416.0 416.0 415.0 415.0 414.0 413.0 411.0 410.0 408.0 407.0 407.0 406.0 404.0 402.0 400.0 394.0 375.0 379.0 390.0 394.0 397.0 397.0 397.0 397.0 402.0 405.0 407.0 407.0 412.0 417.0 423.0 428.0 441.0 448.0 451.0 453.0 457.0 458.0 459.0 460.0 460.0 460.0 458.0 456.0 455.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 404.0 402.0 400.0 398.0 395.0 393.0 392.0 389.0 387.0 385.0 384.0 380.0 377.0 376.0 375.0 374.0 372.0 370.0 369.0 367.0 365.0 362.0 355.0 346.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" 在sun.misc.FloatingDecimal.readJavaFormatString(来源不明) 在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

问题,如果你的rowArray[j]返回了相应的解析的双重价值,那么你不应该在你的代码中有任何问题。查看您的文件是否由\ t(制表符)分隔,而不是由“”(空格)分隔。 因为我试图执行您的代码,并检查得到相同的例外,你得到同样的例外,因为你告诉同样的错误。

+0

该文件中的数字只有1空格分隔,所以在拆分,我改变了代码(“\ t)只是为了(”“),它的工作非常感谢,真的很感谢它! – Daniel

+0

好吧,所以在这个工作之后,我开始寻找数据数组中的最高和最低值。然而,现在我无法得到这个工作xD我添加了导入java.util.Arrays,我也尝试添加java.util。*。之后,我尝试使用的代码如下: – Daniel

+0

Arrays.sort(dmtData); System.out.println(“该区域中的最高峰是:”+ dmtData [dmtData.length-1]); System.out.println(“该区域的最低下标为:”+ dmtData [0]); – Daniel

相关问题