I'm trying to make a program that asks the user to type in 3 cities and the program is supposed to take the 3 cities , and put them in a String Array , the first city in [0],second in [1] and third in [2] , I got it to ask for them , collect the answers but it's only Printing out the first answer, not all 3. Any ideas how I can fix that?
My code looks like this atm
public static void main(String[] args) {
String ans;
String[] favoritStad = new String [3];
Scanner scanner1 = new Scanner (System.in);
System.out.println("skriv in 3 favoritstäder");
String Användarinlägg1 = scanner1.nextLine();
String Användarinlägg2 = scanner1.nextLine();
String Användarinlägg3 = scanner1.nextLine();
favoritStad[0] = Användarinlägg1;
favoritStad[1] = Användarinlägg1;
favoritStad[2] = Användarinlägg1;
System.out.print(Användarinlägg1);
}
Användarinlägg is userinputt , favorit stad is favcity the string "ans" was just an idea I tried to make to collect all 3 answers and print it out but never figured it out
Solved it ! Just needed to add
System.out.print(Användarinlägg2);
System.out.print(Användarinlägg3);
forloop