|
|
|
|
where x..x represent a sequence of (decimal) digits
3.1415 0.31415e1 (= 0.31415×101 = 3.1415) 31.415e-1 (= 31.415×10-1 = 3.1415) |
|
(I used a double precision floating point variable to avoid explaining casting)
Also, you must use the correct syntax construct to write a variable definition
double NameOfVariable ; |
Notes:
|
public class Var01 { public static void main(String[] args) { double x; // Define floating point variable with name "x" System.out.println("Hello Class"); System.out.println(" The variable x contains this number:"); System.out.println(x); // Print variable "x" } } |
Notes:
|
If you compile the program, you will get an error:
Var01.java:11: variable x might not have been initialized System.out.println(x); // Print the content in variable "x" ^ |
This is because the variable x does not have a value yet.
|
VariableName = Value ; |
Notes:
|
public class Var02 { public static void main(String[] args) { double x; // Define floating point variable with name "x" x = 0.31415e1; // Assign 3.1415 to x System.out.println("Hello Class"); System.out.println(" The variable x contains this number:"); System.out.println(x); // Print variable "x" } } |
Notes:
|
How to run the program:
|
Output:
Hello Class The variable x contains this number: 3.1415 |
|
All of the floating point (arithmetic) operators should look familiar to you...
Operator symbol | Operation |
---|---|
+ | addition |
- | subtraction |
* | multiplication |
/ | division |
Result of the integer operation 5.0 + 3.0 is 8.0 Result of the integer operation 5.0 - 3.0 is 2.0 Result of the integer operation 5.0 * 3.0 is 15.0 Result of the integer operation 5.0 / 3.0 is 1.666666666666... |
|
|
Schematically:
![]() |
|
|
|
|
|
All it takes is a bit of imagination
|
(Context: remember the example of "you is a word" and "you are a student" ?)
|
Example:
|
|
|
Logic value | Value used to encode the logic value |
---|---|
true | 1 (integer) |
false | 0 (integer) |
In other words:
|