Problem Description. Arguments for the main method are passed as strings. Strings enclosed in quotation marks are considered as one argument. Write a program to parse arguments from a string. Arguments are separated by spaces. Enclosed strings are considered as one argument. Your program should prompt the user to enter a string and display the arguments, each per line, as shown in the following sample run. Enter the arguments: a friend "good morning" "good afternoon" b   a friend good morning good afternoon b please provide the answer in JAVA

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 2RQ
icon
Related questions
Question

Problem Description. Arguments for the main method are passed as strings. Strings enclosed in quotation marks are considered as one argument. Write a program to parse arguments from a string. Arguments are separated by spaces. Enclosed strings are considered as one argument. Your program should prompt the user to enter a string and display the arguments, each per line, as shown in the following sample run.

<input>

Enter the arguments: a friend "good morning" "good afternoon" b

 

<output>

a

friend

good morning

good afternoon

b

please provide the answer in JAVA

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

the code is not working please can you check again ? 

AutoSave (● Off)
Ans
AlgoDesign src C Main
Bookmarks
ucture
File Edit View Navigate Code
m main
■OHE
Run:
>
Project
AlgoDesign C:\Users\Piincher\IdeaProjects\AlgoDesign
.idea
out
5phyZving
>
META-INF
Main
AlgoDesign.iml
> III External Libraries
src
↑
artifacts
→ 16
AlgoDesign_jar
production
Scratches and Consoles
Version Control ▶ Run
TODO
All files are up-to-date (moments ago)
R021905-\/TRAI||| V
Refactor Build Run Tools VCS Window Help
Type here to search
℗ Problems
1
2
good.png
6
7
8
9
ERGREREE
10
11
12
13
14
15
16
17
Main.java
A
A
A
e
밥
O
Search (Alt+0)
import java.util.*;
2 usages
public class Main
> Terminal ▸ Services
{
Ĥ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
AlgoDesign.jar - Main.java
String str = sc.nextLine();
for(int i=0; i < str.length(); i++){
if(str.charAt(i) == ''){
System.out.println();
}
else if(str.charAt(i) == '"''){
Profiler
for(int j=i+1; j < str.length(); j++){
if(str.charAt(j) == '"'){
i =j+1;
Main X
Program Files\JetBrains\IntelliJ IDEA 2022.2.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Piincher\IdeaProjects\AlgoDesign\out\production\AlgoDesign Main
Show all
H
Build
X
W
Main ▾
19
Sign in
ĠÁCa
■
□Ơ
Q ▸
10:45 CRLF UTF-8 4 spaces
74°F Partly cloudy. 4) ENG
))) Database
Notifications
V
lace
Share
ct ✓
7:55 AM
9/3/2022
X
100%
Transcribed Image Text:AutoSave (● Off) Ans AlgoDesign src C Main Bookmarks ucture File Edit View Navigate Code m main ■OHE Run: > Project AlgoDesign C:\Users\Piincher\IdeaProjects\AlgoDesign .idea out 5phyZving > META-INF Main AlgoDesign.iml > III External Libraries src ↑ artifacts → 16 AlgoDesign_jar production Scratches and Consoles Version Control ▶ Run TODO All files are up-to-date (moments ago) R021905-\/TRAI||| V Refactor Build Run Tools VCS Window Help Type here to search ℗ Problems 1 2 good.png 6 7 8 9 ERGREREE 10 11 12 13 14 15 16 17 Main.java A A A e 밥 O Search (Alt+0) import java.util.*; 2 usages public class Main > Terminal ▸ Services { Ĥ public static void main(String[] args) { Scanner sc = new Scanner(System.in); AlgoDesign.jar - Main.java String str = sc.nextLine(); for(int i=0; i < str.length(); i++){ if(str.charAt(i) == ''){ System.out.println(); } else if(str.charAt(i) == '"''){ Profiler for(int j=i+1; j < str.length(); j++){ if(str.charAt(j) == '"'){ i =j+1; Main X Program Files\JetBrains\IntelliJ IDEA 2022.2.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Piincher\IdeaProjects\AlgoDesign\out\production\AlgoDesign Main Show all H Build X W Main ▾ 19 Sign in ĠÁCa ■ □Ơ Q ▸ 10:45 CRLF UTF-8 4 spaces 74°F Partly cloudy. 4) ENG ))) Database Notifications V lace Share ct ✓ 7:55 AM 9/3/2022 X 100%
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Methods of StringBuilder class
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT