So i got a programm that asks the user to type in the 3 favorite cities , it stores them in Array and prints them later out to the user. What im trying to do now is making the programm ask the user for how many favorite cities he/she got?the user types in a number wich will give the user the oppertunity to type in that ammount of favorit cities and later on print them out.
Problem is i really have no idea how to do this could anyone help?
Please explain the code incase you help so i can understand :) , Sorry for my bad English not my primary language!
My code atm looks like this :
package com.example.array.main;
import java.util.Scanner;
public class Application {
public static void main(String[] args) {
String[] favoritCity = new String [3];
Scanner scanner1 = new Scanner (System.in);
System.out.println("skriv in 3 favoritstäder");
String userIn1 = scanner1.nextLine();
String userIn2 = scanner1.nextLine();
String userIn3 = scanner1.nextLine();
favoritCity[0] = userIn1;
favoritCity[1] = userIn2;
favoritCity[2] = userIn3;
System.out.println(userIn1);
System.out.println(userIn2);
System.out.println(userIn3);
}
}
Before to define your Array size, you can use your scanner to ask for the number of cities, for example: