Liutauras Vilda wrote:That "if" statement within while loop body seems redundant to me.
You're checking that within while loop condition, just in a wrong way, as it was pointed out already.
Why you all the time adding to 0 position? Wouldn't do-while loop look nicer in there?
Yes of course was posting the wrong unedited code..
This is what it should look like and my question still remains...
public class WheaterStation {
public static void main(String[] args) {
ArrayList<String> city = new ArrayList<String>();
Scanner sc = new Scanner(System.in);
System.out.println("Add a city");
int i = 0;
String s = "";
while (!s.equals("q")){
s = sc.nextLine();
city.add(s);
i++;
}
city.remove("q");
for (String x : city)
System.out.println(x);
}
}
"Trying to make a list of cities with added weather in form of (x) degreese celsius. A list of cities. The scan is goiing to ask for name(city) and the wheather(degreese) of that city.
I´m using this while loop but cant find a nice why to brake it. As it is now the "Q" Im using to break the loop is stored as well in the array.
And therefore I have the remove line right after which dont feel as the best way to do it.
Also need a way to store an integer for the temperature in every city but Im not alowed to use hashmaps. "