Objectives:
In the Interactions pane, type in
each of the following sequences of Java expressions and statements to see
what they do. Note: You should “Reset Interactions” after each sequence
by pulling down the menu from the upside down triangle in the upper right of
the Interactions pane.
int x = 7;
x = x + 5;
System.out.println("The result is:" + x);
double x = 2.5;
int y =
5;
System.out.println("The product of two variables is: " + x*y);
System.out.println("But, cast product to (int), then:" + (int)(x*y));
System.out.println("Is this true that
2 > 5 ? " +
"Let's see, it's ... " + (2 > 5) +
"!!!");
The
Interactions Pane is great for testing out code and we will be using it a
lot. But we will also want to be able to have a Java class that forms
a program application that can be executed on its own. From
the Package Explorer select the class MyProgram. This class has a
"main" method that is executed when we execute the class. You
can execute this program by selecting Run As under the Run menu (or the Run
icon in the toolbar) and then choosing Java Application. The output of
the program will appear in the Interactions Pane.
| Assignment: Edit the code in MyProgram so that it prints out your name. |