Objectives:
Select the Tab
on the bottom for the Interactions pane. Type each of the following sequences of Java expressions and statements
in the Interactions Pane to see
what they do. Note: You should "Reset Interactions" after each sequence
by selecting the Reset Interactions under the Tools menu or by right
clicking the Interaction Pane and selecting Reset Interactions from the
pop-up menu.
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) +
"!!!");
| Assignment: In a text or word document, write out a brief description of what each of the three code fragments is doing and why it works the way it does. |
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. Under the File
menu select Open and then browse to your cs116 folder and open the file MyProgram.java. This class has a
"main" method that is executed when we execute the class. You
can execute this program by first selecting Compile in the Toolbar and then
click Run. The output of
the program will appear in the Interactions Pane.
| Assignment: Edit the code in MyProgram so that it prints out both your names. |