Write code that inserts userItem into the output string stream itemsOSS until the user enters "Exit". Each item should be followed by a space. Sample output if user input is "red purple yellow Exit": red purple yellow --------------------- import java.util.Scanner; import java.io.PrintWriter; import java.io.StringWriter; public class StringStreamOutput { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); String userItem; StringWriter itemCharStream = new StringWriter(); PrintWriter itemsOSS = new PrintWriter(itemCharStream); System.out.println("Enter items (type Exit to quit):"); userItem = scnr.next(); while (!userItem.equals("Exit")) { /* Your solution goes here */ userItem = scnr.next(); } userItem = itemCharStream.toString(); System.out.println(userItem); } }
Write code that inserts userItem into the output string stream itemsOSS until the user enters "Exit". Each item should be followed by a space. Sample output if user input is "red purple yellow Exit":
red purple yellow
---------------------
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.StringWriter;
public class StringStreamOutput {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
String userItem;
StringWriter itemCharStream = new StringWriter();
PrintWriter itemsOSS = new PrintWriter(itemCharStream);
System.out.println("Enter items (type Exit to quit):");
userItem = scnr.next();
while (!userItem.equals("Exit")) {
/* Your solution goes here */
userItem = scnr.next();
}
userItem = itemCharStream.toString();
System.out.println(userItem);
}
}

![CHALLENGE
12.2.3: Output using string stream.
АCTIVITY
Write code that inserts userltem into the output string stream itemsOSS until the user enters "Exit". Each item should be followed
by a space. Sample output if user input is "red purple yellow Exit":
red purple yellow
374934.2421584.qx3zqy7
1 import java.util.Scanner;
2 import java.io.PrintWriter;
3 import java.io.StringWriter;
1 test
passed
4
5 public class StringStreamOutput {
All tests
passed
public static void main (String [] args) {
Scanner scnr =
6.
7
new Scanner(System.in);
8
String userItem;
9
StringWriter itemCharStream
PrintWriter items0SS
10
new StringWriter();
= new PrintWriter(itemCharStream);
11
12
13
System.out.println("Enter items (type Exit to quit):");
14
userItem
scnr.next();
15
Run
Need help?
Feedback?](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F945892cb-ed29-4ccf-b18f-dab49f1692d9%2F57814517-d76e-44da-9de8-dcb36a287c27%2Fxy9zpnk_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images









