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
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
- Design and implement a function with no input parameters. The function keeps receiving a number...
- Design and implement a function with no input parameters. The function keeps receiving a number from input (user) and adds the numbers together. The application keeps doing it until the user enter 0. Then the application will stop and print the total sum and average of the numbers the user had entered.
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT