Saturday, February 13, 2016

Exercise 1.2

QUESTION


Before you do anything else, find out how to compile and run a Java program in your environment. Some environments provide sample program similar to the example in Section 1.5.
  1. Type in the “Hello, world” program, then compile and run it.
  2. Add a print statement that prints a second message after the “Hello, world!”. Something witty like, “How are you?” Compile and run the program again.
  3.  Add a comment to the program (anywhere), recompile, and run it again. The new comment should not affect the result.
The exercise may seem trivial, but it is the starting place for many of the programs we will work with. To debug with confidence, you have to have confidence in your programming environment. In some environments, it is easy to lose track of which program is executing, and you might find yourself trying to debug one program while you are accidentally running another. Adding (and changing) print statements is a simple way to be sure that the program you are looking at is the program you are running.


SOLUTION


public class ThinkJava1_Ex2 {
 public static void main (String[]args){
System.out.println("Hello, world");
System.out.println("How are you?");
}
}

//This is a comment.

No comments:

Post a Comment