Java Reference
In-Depth Information
The following Java program shows the effect of the preceding statements:
// This program illustrates how data in the variables are
// manipulated.
public class
Example2_13
{
public static void
main(String[] args)
{
int
num1;
int
num2;
double
sale;
char
first;
String str;
num1 = 4;
System.out.println("num1 = " + num1);
num2 = 4 * 5 - 11;
System.out.println("num2 = " + num2);
sale = 0.02 * 1000;
System.out.println("sale = " + sale);
first = 'D';
System.out.println("first = " + first);
str = "It is a sunny day.";
System.out.println("str = " + str);
}
}
Sample Run:
num1 = 4
num2 = 9
sale = 20.0
first = D
str = It is a sunny day.
For the most part, the preceding program is straightforward. Let us take a look at the
output statement:
System.out.println("num1 = " + num1);
This output statement consists of the string
"num1 = "
,
+
, and the variable
num1
. Here,
the value of
num1
is concatenated with the string
"num1 = "
, resulting in the string
"num1 = 4"
, which is then output. The meanings of other output statements are similar.
Search WWH ::
Custom Search