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
icon
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);
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
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Files and Directory
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education