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

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...
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.
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
Unix command lines. A) Assume that your current working directory is NOT the same as your...
Unix command lines. A) Assume that your current working directory is NOT the same as your home directory. Print all file and subdirectory names of your home directory into a file named file2. B) Copy the text from line 11 to line 20 of a given file input.txt and append the copied text at the end of the file output.txt. (Assume that the file input.txt contains more than 20 lines of text contents) C) Count and display the total number...
For a college, develop an intelligent timetable generator. Some of the parameters to be considered are...
For a college, develop an intelligent timetable generator. Some of the parameters to be considered are number of staff, number of subjects, number of batches – practical/theory (shift – yes/no), number of subjects the staff would teach, number of hours the staff has load, number of classrooms and laboratories. The system needs to tackle clashes as well. in python plz fast
Maximum value and its index in an array java program that: Receive as input in command...
Maximum value and its index in an array java program that: Receive as input in command line the size of an array (n) Generate an array with numbers between 1 and 100 (inclusive 1 and 100) with the given size (a) Print the array with the format: {a, b, c, ..., x}, for instance {1, 2} Compute and print in the console the following: maximum value in the array one index on which the maximum value appears (a number from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT