Showing posts with label double. Show all posts
Showing posts with label double. Show all posts

Tuesday, January 8, 2013

Incrementing a number ++


Increment - increase a value.

The increment operator is a double plus ++

The increment operator increases the value to it's left by 1.

Example use with int:

int one = 10;
one ++;

In the first line, an int variable called one is declared and assigned a value of 10.

In the second line, the increment operator is applied to the variable called one to increment it's value.

The result is that the variable called one, now has a value of 11.



Example use with double:

double one = 12.55;
one ++;

In the first line, a double variable called one is declared and assigned a value of 12.55.

In the second line, the increment operator is applied to the variable called one to increment it's value.

The result is that the variable called one, now has a value of 13.55.

Note that where the increment operator is used with the double data type, the increment value is 1 significant number (the number on the left of the floating point is incremented).

See also Decrementing a number

Decrementing a number --


Decrement - decrease a value.

The decrement operator is a double minus --

The decrement operator decreases the value to it's left by 1.

Example use with int:

int one = 10;
one --;

In the first line, an int variable called one is declared and assigned a value of 10.

In the second line, the decrement operator is applied to the variable called one to decrement it's value.

The result is that the variable called one, now has a value of 9.



Example use with double:

double one = 12.55;
one --;

In the first line, a double variable called one is declared and assigned a value of 12.55.

In the second line, the decrement operator is applied to the variable called one to decrement it's value.

The result is that the variable called one, now has a value of 11.55.

Note that where the decrement operator is used with the double data type, the decrement value is 1 significant number (the number on the left of the floating point is decremented).

See also Incrementing a number


Sunday, June 3, 2012

the double data type

A double is a numeric data type. Suitable for storing floating point (decimal) numbers such as weight, length, etc. Any kind of number with a "point something' in it such as 7.6, 10.5, 1.2, etc.

Where a double has not been assigned a value, by default it's value is 0.0d.

The format for declaring a double variable is:

   Type identifier;

Where the Type is double and the identifier is weight:

   double weight;

...and where a value of 100.50 has been assigned:

   double weight = 100.50;


You can declare a double in one statement and assign it a value in another statement:

   double weight;
   // other statements...
   weight = 100.50;



See also:

"Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)" ( http://bit.ly/xesQuj )
"Java For Complete Beginners - Double variables" ( http://bit.ly/ZzYTJ9 )