Note that there are some explanatory texts on larger screens.

plurals
  1. PO(Java) Array out of bounds exception
    primarykey
    data
    text
    <p>So, I've been working on some code for my computer science course to calculate heat index. I'm having troubles loading the data from the text file I'm instructed to work with into the array the program is going to be working with. The block you see commented out is another solution I was trying, which doens't work either... How should I go about fixing it? Thanks!</p> <pre><code>import java.util.Scanner; import java.io.File; import java.io.IOException; public class HeatIndex { public static void main(String [] args) throws IOException { Scanner keyWestHumidScan = new Scanner(new File("KeyWestHumid.txt")); Scanner keyWestTempScan = new Scanner(new File("KeyWestTemp.txt")); int counter1 = 0; int counter2 = 0; int [] keyWestHumid = {}; double [] keyWestTemp = {}; String header1 = " Heat index: Key West, Florida "; String header2 = "\n Months \n "; String [] months = {"Jan ", "Feb ", "Mar ", "Apr ", "May ", "Jun ", "Jul ", "Aug ", "Sep ", "Oct ", "Nov ", "Dec ", "Avg \n"}; String header3 = "*************************************************************************************"; String [] Labels = {"Temp (F) \n", "Hudimitiy (%) \n", "HI (F) "}; //read keyWestHumid into array while(keyWestHumidScan.hasNext()) { keyWestHumid[counter1] = keyWestHumidScan.nextInt(); counter1++; //String data1_parse = keyWestHumidScan.next(); ///int data1 = Integer.parseInt(data1_parse); //keyWestHumid[counter1] = data1; //counter1++; } //read keyWestTemp into array while(keyWestTempScan.hasNext()) { String data2_parse = keyWestTempScan.next(); double data2 = Double.parseDouble(data2_parse); keyWestTemp[counter2] = data2; counter2++; } System.out.println(header1); System.out.print(header2); for(String headData:months) { System.out.print(headData); } System.out.println(header3); for(String headData:Labels) { System.out.print(headData); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload