Java - How do I output the statement exactly as it shows? How can I get rid of the commas at the end? Don't get rid of each comma, just the ones at the end of the output.
Java - How do I output the statement exactly as it shows? How can I get rid of the commas at the end? Don't get rid of each comma, just the ones at the end of the output.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Java - How do I output the statement exactly as it shows? How can I get rid of the commas at the end? Don't get rid of each comma, just the ones at the end of the output.
![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 separated by a comma, one
ordering per line.
When the input is:
Julia Lucas Mia -1
hen 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
1 import java.util.Scanner;
2 import java.util.ArrayList;
NM4 in 6100
3
4 public class PhotoLineups {
5
7
8
9
10
#2#99998=22**222*8========779#!
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
30
31
33
34
35
36
37
}
32 public static void main(String[] args) {
38
39
40
41
42
43
public static void printAllPermutations (ArrayList<String> permList, ArrayList<String> nameList) {
if(nameList.isEmpty()) {
44
for(int i = 0; i <permList.size(); i++) {
System.out.print(permList.get(i) +", ");
}
System.out.println();
}else{
for(int i = 0; i <nameList.size(); ++i) {
ArrayList<String> newPerm = new ArrayList<String> (permList);
newPerm.add(nameList.get(i));
ArrayList<String> newNameList = new ArrayList<String>(nameList);
newNameList.remove(i);
printAllPermutations (newPerm, newNameList);
}
}
Scanner scnr = new Scanner(System.in);
ArrayList<String> nameList = new ArrayList<String>();
ArrayList<String> permList = new ArrayList<String>();
string name;
while(true) {
name = scnr.next();
if(name.equals("-1")) break;
nameList.add(name);
}
printAllPermutations (permList, nameList);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1c870776-4927-4fbd-b218-f5b27740c439%2F17e43092-e1ea-4ac4-b009-59a5b0c5cd3d%2Fzpiok8_processed.png&w=3840&q=75)
Transcribed Image Text: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 separated by a comma, one
ordering per line.
When the input is:
Julia Lucas Mia -1
hen 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
1 import java.util.Scanner;
2 import java.util.ArrayList;
NM4 in 6100
3
4 public class PhotoLineups {
5
7
8
9
10
#2#99998=22**222*8========779#!
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
30
31
33
34
35
36
37
}
32 public static void main(String[] args) {
38
39
40
41
42
43
public static void printAllPermutations (ArrayList<String> permList, ArrayList<String> nameList) {
if(nameList.isEmpty()) {
44
for(int i = 0; i <permList.size(); i++) {
System.out.print(permList.get(i) +", ");
}
System.out.println();
}else{
for(int i = 0; i <nameList.size(); ++i) {
ArrayList<String> newPerm = new ArrayList<String> (permList);
newPerm.add(nameList.get(i));
ArrayList<String> newNameList = new ArrayList<String>(nameList);
newNameList.remove(i);
printAllPermutations (newPerm, newNameList);
}
}
Scanner scnr = new Scanner(System.in);
ArrayList<String> nameList = new ArrayList<String>();
ArrayList<String> permList = new ArrayList<String>();
string name;
while(true) {
name = scnr.next();
if(name.equals("-1")) break;
nameList.add(name);
}
printAllPermutations (permList, nameList);
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 4 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education