Home > Articles

  • Print
  • + Share This
This chapter is from the book

Exercises

  • 1.1.1 Write a program that prints the Hello, World message 10 times.

  • 1.1.2 Describe what happens if you omit the following in HelloWorld.java:

    1. public

    2. static

    3. void

    4. args

  • 1.1.3 Describe what happens if you misspell (by, say, omitting the second letter) the following in HelloWorld.java:

    1. public

    2. static

    3. void

    4. args

  • 1.1.4 Describe what happens if you put the double quotes in the print statement of HelloWorld.java on different lines, as in this code fragment:

    System.out.println("Hello,
                        World");
  • 1.1.5 Describe what happens if you try to execute UseArgument with each of the following command lines:

    1. java UseArgument java

    2. java UseArgument @!&^%

    3. java UseArgument 1234

    4. java UseArgument.java Bob

    5. java UseArgument Alice Bob

  • 1.1.6 Modify UseArgument.java to make a program UseThree.java that takes three names as command-line arguments and prints a proper sentence with the names in the reverse of the order given, so that, for example, java UseThree Alice Bob Carol prints Hi Carol, Bob, and Alice.

  • + Share This
  • 🔖 Save To Your Account