System.out.println("x value is 100.0");
int
|
: an whole number between ~+/- 2,000,000,000 |
double
|
: a decimal number between +/- 10+/-38 |
boolean
|
: either true or false
|
char
|
: a single character |
type variableName;
For example:
double x;
x = 100.0;
double x = 100.0;
Infact, this is quite usual during initialisation (the first time you use a variable). After that, you don't do the label creation bit again.
double nearX = x + 1.0;
System.out.println("x = " + x);
which prints x = 100.0
; note that "+" joins two things for printing if one is text, and the difference between "x = "
which is in quotes, so is text, and x
, which isn't, and is therefore a variable, the value of which is printed.
x = 200.0;
Note that you don't need to create a new label, you just give a new value to the old one.
x = x + 1.0;
The right side is assessed first, and the answer (201.0) replaces what is currently in x (200.0).
+ | : add |
- | : subtract |
* | : multiple |
/ | : divide |
% | : modulus |
++ | : add one |
5 % 2 = 1
x++
is the same as x = x + 1
i = 6 + 6 / 3;
will give i as 8, not 4.
i = (6 + 6) / 3;
int m = 3;
double i = m;
gives i as 3.0.
(target type) variable;
for example,
int numberOfPokemon = 150;
byte number;
number = (byte)numberOfPokemon;
float f = (float) 2.5;
float f = 2.5f;
i = 11 / 5;
gives i = 2 remainder nothing, even if i is a double.
double d = 3.0 / 2.0;
not
double d = 3 / 2;
int x;
declares/creates an integer label, called x.
x = 100;
assigns it the value 100.
int x = 100;
But from then on, you just use the label, thus:
x = 200;