Question

Write a full program that will accept any number of command line arguments and print them...

Write a full program that will accept any number of command line arguments and print them to the screen.

Suppose your program is called Print.java.

When the command java Print hello goodbye you is run, the output will be

hello

goodbye

you

Write a full program that will accept exactly  three command line arguments that can be interpreted as integers, and will add them up. If there aren't exactly 3 command line arguments, print an error message and terminate the program.

Suppose your program is called Add.java.

Then running the command java Add 1 2 3 will output 6, and running java Add, for example, will cause the program to shut down.

Consider the following recursive method:

public static int mystery (int n) {

   if (n ==0)

   return 1;

   else

return 2 * mystery(n-1);

}

What is returned by a call to mystery(7)?

What is computed by the mystery method?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

As multiple questions are there, answering the first one as per guidelines to me

Explanation:

All the command line arguments are stored in the array args which is default passed in main method.

So, using a for loop and iterating till the args.length , printing each argument in new line.

Code:

class Print

{

public static void main(String[] args) {

for(int i=0; i<args.length; i++)

{

System.out.println(args[i]);

}

}

}

saved Print.java class Print 1 public static void main(String[] args) { for(int i=0; i<args.length; i++) Ovo AWN System.out.p

Output:

> javac Print.java > java Print hello goodbye you hello goodbye you

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
Write a full program that will accept any number of command line arguments and print them...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Command Line Arguments: Write a program in C Compiler that will accept two integers on command...

    Command Line Arguments: Write a program in C Compiler that will accept two integers on command line, subtract the second from the first (1st - 2nd) and display the answer. It exactly two numbers are not provided on command line, there should be a simple error message printed and the program ends with no further input, output, or calculations

  • In C, Write a program that can accept an arbitrary number of command line arguments, e.g....

    In C, Write a program that can accept an arbitrary number of command line arguments, e.g. program must do the following: program needs to split each of the arguments into two halves based on the length of a string. Specifically, the first half will be [0, n/2) and the second half will be [n/2] where n is the length of the string and n > 1. For instances, hello is split into two halves: he and llo. Similarly, world! is...

  • Write a program that will accept two integers on command line, use the swap subprogram to...

    Write a program that will accept two integers on command line, use the swap subprogram to swap them, and then print the two numbers out. For example, I enter a.out 10 15 and the output that would print is 15 10. Please note that if exactly two numbers are not provided on command line, your program should display an error message and end with no further action. The programming language is C Compiler.

  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

  • 1) Write a C program that displays all the command line arguments that appear on the...

    1) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 2) Write a C program which displays the sum of the command line arguments. Hint: use sscanf to convert the decimal arguments (which are strings) to binary numbers that...

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • FOR JAVA Write a program that takes two command line arguments: an input file and an...

    FOR JAVA Write a program that takes two command line arguments: an input file and an output file. The program should read the input file and replace the last letter of each word with a * character and write the result to the output file. The program should maintain the input file's line separators. The program should catch all possible checked exceptions and display an informative message. Notes: This program can be written in a single main method Remember that...

  • Write a bash shell script to print the number of command line arguments and list of...

    Write a bash shell script to print the number of command line arguments and list of command line arguments 3. 12]

  • After reading pages 330 - 336, write a program that takes two command line arguments which...

    After reading pages 330 - 336, write a program that takes two command line arguments which are file names. The program should read the first file line by line and write each line, in reverse order, into the second file. The program should include a "usage" method that displays the correct command line syntax if two file names are not provided. Example: if my input file says Hello, World! then my output file will contain !dlroW ,olleH Hints: Use CaesarCipher...

  • Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer...

    Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where each value is between is 1 and n, and displays true if there are any duplicate values, false otherwise. CODE IN JAVA and NO IMPORT STATEMENTS CAN BE USED

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT