Skip to content

Instantly share code, notes, and snippets.

@51enra
Created November 18, 2019 13:15
Show Gist options
  • Save 51enra/1cf862a505c418d80c5148c37324ff8d to your computer and use it in GitHub Desktop.
Save 51enra/1cf862a505c418d80c5148c37324ff8d to your computer and use it in GitHub Desktop.
Quest 4: Arrays and Loops
class Movies {
public static void main(String[] args) {
String[] movieNames = { "Raiders of the Lost Ark", "Indiana Jones and the Temple of Doom",
"Indiana Jones and the Last Crusade" };
String[][] movieMainActors = new String[][] { { "Harrison Ford", "Karen Allen", "Paul Freeman" },
{ "Harrison Ford", "Kate Capshaw", "Ke Huy Quan" },
{ "Harrison Ford", "Sean Connery", "Denholm Elliot" } };
String actorString;
for (int i = 0; i < movieNames.length; i++) {
actorString = "";
for (String actor : movieMainActors[i]) {
actorString += (actor + ", ");
}
actorString = actorString.substring(0, actorString.length()-2) + ".";
System.out.println("In the movie " + movieNames[i] + ", the main actors are: " + actorString);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment