Alright, so basically, I am trying to write a simple program. The purpose is that it reads a file (the file is a set of numbers that would fill a 401 by 401 table) and then writes the data into an array and prints the array to the console. This is going ot be used later to find specific numbers, so like I will write code to find the highest and lowest numbers in the array etc. I don't know how yet, but I haven't got the program working yet. Every time I run this program, the exact error I get is as follows.
Exception in thread "main" java.lang.NumberFormatException: For input string: "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 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 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" at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source) at java.lang.Double.parseDouble(Unknown Source) at MultiArray.main(MultiArray.java:19)
Now, here is the code for my program.
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: ");
}
}
Thanks for any help, I promise once I understand java I'll do my best to answer questions on here :)