Posted By:
fabrice_khlok
Posted On:
Wednesday, July 31, 2002 07:44 AM
hey guys i have a question: I am a newcomer to java, maybe someone can help. I am working on an excercise and am stuck. the following table is given: months jan feb mar ......dec hoursofsun 211 220 322 ....... I need to store both the months and hoursofsun into two 1-dimensional arrays. how can i read the names of months from the text and store them into seperate cells? what i did was: String[] months : {"jan","feb", "mar".....] but i would like to know how to do it the other way. second part: for the second array: I did the follo
More>>
hey guys i have a question:
I am a newcomer to java, maybe someone can help. I am working on an excercise and am stuck.
the following table is given:
months jan feb mar ......dec
hoursofsun 211 220 322 .......
I need to store both the months and hoursofsun into two 1-dimensional arrays.
how can i read the names of months from the text and store them into seperate cells?
what i did was:
String[] months : {"jan","feb", "mar".....]
but i would like to know how to do it the other way.
second part:
for the second array:
I did the following and got some jind of runtime error:
I'm not sure what's wrong, but could someone tell me how to store numbers from a file (on one line) into individual cells?
thx
{
final int SIZE = 12;
StringTokenizer data;
FileReader file = new FileReader("a:\hours.txt");
BufferedReader inputFile = new BufferedReader(file);
int[]hours = new int[SIZE];
for (int index=0; index != SIZE; index++)
{
data = new StringTokenizer(inputFile.readLine());
hours[index] = new Integer(data.nextToken()).intValue();
}
for (int index=0; index != SIZE; index++)
{
screen.println(hours[index]);
}
}
<<Less