This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I've created a switch statement and in the second case, i'm getting an error saying that i need to initialised the cities variable. i dont know/understand what to put in case 2 to fix it. cities is the array that i have created from reading data from a text file.
Thanks in advance
System.out.println("Cities and temperatures have been read from file");
Here's your code cleaned up a little. You declare your cities variable inside the 'case 1' block. If your code goes directly into case 2, you've never initialized your variable, since you'd skip line 4. you can declare it outside the case statement entirely.. something like
You still may have problems, though, depending on the structure of the rest of your code.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors