Question

In: Computer Science

• Develop an "Echo" command that returns the parameters on different lines. Example: For input "$...

• Develop an "Echo" command that returns the parameters on different lines.
Example: For input
"$ Java Echo Hello world!"
The answer will be:
"Hello
world
! ”

using java programming language

Solutions

Expert Solution

Every line of the code is clearly explained in the comments of the code itself.

CODE--

import java.util.*;
public class Echo
{
   public static void main(String[] args)
   {
       Scanner sc=new Scanner(System.in);
       String cmd;
      
       //read the command from the user
       cmd=sc.nextLine();
      
       //store each word in a separate array variable
       String[] words=cmd.split("[!. ?\"]");
      
       //Echo or display the given output
       System.out.print("\"");
      
       //we start from index 4 because
       //the indices before 4 contain the command
       //which is not required to be displayed
       for(int i=4;i<words.length;i++)
       {
           System.out.println(words[i]);
       }
      
       //here we check if there is any punctuation at the end
       if(cmd.charAt(cmd.length()-2)=='!' ||cmd.charAt(cmd.length()-2)=='.' ||cmd.charAt(cmd.length()-2)=='?')
       {
           //if so we display the punctuation
           System.out.println(cmd.charAt(cmd.length()-2)+"\"");
       }
       sc.close();
   }
}

Output Screenshot:

Please upvote if you liked the effort.


Related Solutions

The following .py script takes a users input of search parameters on command line, creates a...
The following .py script takes a users input of search parameters on command line, creates a custom search URL, then returns top 5 result links from Google Scholar. Alter the below code so that the script opens up each found link in a separate browser window (or tabbed windows in a single browser). ——.py import requests, sys, webbrowser from bs4 import BeautifulSoup print("Searching for " + "+".join(sys.argv[1:])) myres = requests.get("https://scholar.google.com/scholar? hl=en&q=" + "+".join(sys.argv[1:]) + "&*") soup = BeautifulSoup(myres.text, "html.parser") elems...
Develop a function DNF that takes as input a proposition and returns as output a logically...
Develop a function DNF that takes as input a proposition and returns as output a logically equivalent proposition in DNF. Hint: Adapt the CNF function.
Using, for example, the command “=IF(RAND()<0,4;1;0)” in Excel, simulate 40 different realizations with n = 60...
Using, for example, the command “=IF(RAND()<0,4;1;0)” in Excel, simulate 40 different realizations with n = 60 and the true supporting rate to be 40%. In order to “freeze” the output generated by Excel, select the cells with all 0s and 1s values that have been randomly generated using the above mentioned command, copy them and paste them (using the paste special option) as values back on top of the cells. Then in each of the 40 different simulated “datasets” calculate...
Using, for example, the command “=IF(RAND()<0,4;1;0)” in Excel, simulate 40 different realizations with n = 60...
Using, for example, the command “=IF(RAND()<0,4;1;0)” in Excel, simulate 40 different realizations with n = 60 and the true supporting rate to be 40%. In order to “freeze” the output generated by Excel, select the cells with all 0s and 1s values that have been randomly generated using the above mentioned command, copy them and paste them (using the paste special option) as values back on top of the cells. Then in each of the 40 different simulated “datasets” calculate...
Twin elements Create a program that: Input: Receive as input in command line the sizes m...
Twin elements Create a program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (mxn) Compute: Compute the number of elements that have a neighbour (up, down, left or right) with the same...
In C++, develop a menu program which reads in data from 4 different input files -...
In C++, develop a menu program which reads in data from 4 different input files - appetizers, entrees, desserts, and drinks. Then, record the item information ordered by the customer for each item selected. When finished, display all items ordered to the screen with the subtotal, tax (10% for easy math), and the total. Be sure to get tip as well. Then, ensure enough payment was received before generating an output file receipt which can be printed off. Use functions...
Stata command for running an RDD with 2 treamtents and cut-off lines
Stata command for running an RDD with 2 treamtents and cut-off lines
For Linux: Write a command to append the top 20 lines of the file seq.fasta to...
For Linux: Write a command to append the top 20 lines of the file seq.fasta to a second file named combined.seq.
Need the history of amazon echo as a device. For example: when it was created, when...
Need the history of amazon echo as a device. For example: when it was created, when did amazon decide to begin creating thiz device, which of Amazon's subsidiary was developing echo. And some general things from echo's history
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT