Java Reference
In-Depth Information
Tutorial: Using Primitive Variables
For each of these tests, try to determine what the result will be (and why) before entering and executing the source
code. The answer and explanation for each test will appear after the tutorial.
1.
Create a new Java class in c5 called MathTestApp with a main method.
In the main method, define an int variable called intTest and set its value to 3, and define
a double variable called doubleTest with a value of 2.0.
2.
3.
Add the following two statements after the variable definitions and run MathTestApp:
System.out.println(++intTest);
System.out.println(intTest++);
4.
Comment out the previous println statements, add the following statements, and run
MathTestApp:
System.out.println(intTest/2);
System.out.println(intTest/2.0);
System.out.println(intTest/doubleTest);
5.
Comment out the previous println statements, add the following statements, and run
MathTestApp:
System.out.println(Math.pow(doubleTest, intTest)/(2.0*3.0));
6.
Comment out the previous println statements, add the following statements, and run
MathTestApp:
System.out.println(Math.pow(doubleTest, intTest)*3/2);
System.out.println(Math.pow(doubleTest, intTest)*(3/2));
7.
Comment out the previous println statements, add the following statements, and run
MathTestApp:
System.out.println(intTest);
System.out.println(intTest++/2);
System.out.println(intTest);
System.out.println(++intTest/2);
System.out.println(intTest);
8.
Comment out the previous println statements, add the following statements, and run
MathTestApp:
System.out.println(doubleTest++ + ++intTest);
System.out.println(doubleTest + " " + intTest);
9.
Comment out the previous println statements, add the following statements, and run
MathTestApp:
System.out.println(" " + Math.pow(doubleTest++,
++intTest) + doubleTest++);
System.out.println(doubleTest);
10.
Print out a copy of the MathTestApp source code.
 
Search WWH ::




Custom Search