تم الحل ✓
categoryعلوم الحاسوب
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
14.9 LAB: All permutations of names
Write a program that lists all ways people can line up for a photo (all permutations of a list of Strings). The program will read a list of one
word names (until -1), and use a recursive method to create and output all possible orderings of those names, one ordering per line.
When the input is:
Julia Lucas Mia -1
then the output is (must match the below ordering):
Julia Lucas Mia
Julia Mia Lucas
Lucas Julia Mia
Lucas Mia Julia
Mia Julia Lucas
Mia Lucas Julia
LAB
ACTIVITY
14.9.1: LAB: All permutations of names
0/10
PhotoLineups.java
6 public class PhotoLineups {
7
public static void allPermutations (ArrayList<String> permList, ArrayList<String> name List, int index) {
if (index == nameList.size()) {
String res =
for (int i = 0; i < nameList.size(); i++) {
8
9
10
11
12
13
14
}
15
16
17
18
}
19
20
21
23
24
25
26
222222222
res =
res +=nameList.get(i)+" ";
res.trim();
permList.add(res);
System.out.println(res);
for (int i = index; i < namelist.size(); i++) {
Collections.swap (nameList, index, i);
allPermutations (permList, name List, index + 1);
Collections.swap (nameList, index, i);
}
// TODO: Write method to create and output all permutations of the list of names.
Develop mode
Submit mode
Load default template...
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
second box.
Enter program input (optional)
If your code requires input values, provide them here.
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.