View Single Post
Ambitious contributor
6Sep2012,14:06  
pein87's Avatar
When you create a variable, array, or method you need to give it a data type. I wont go to in-depth with all the various data types but I will list just a few. Java like C/C++ and C# have strict typing. What that means is you need to say what type of data a variable, array, or method is or will return. These data types include text, numbers, and objects.

Number data types include int, float, and double

int is for any whole number with in a certain range and includes negative numbers as well.

Code: Java
int age = 23;
int temp - 32;

float is a single precision point decimal number

Code: Java
float pressure = 5.5;
float meters = 3.7;

double is a double precision point decimal and all decimal types are considered double.

Code: Java
double percent = 98.56;
double ratio = 1.56;

For text there is char and String

char is for a single character

Code: Java
char money = '$';
char percent = '%';

String is for text

Code: Java
String name = "Pein";
String quote = "Never die alone.";

Type casting/conversion is when you change one type into another.

Code: Java
double percent = 89.45;

int num = (int)percent;

As you can see I turned the percent variable into an int type by adding (int) in front of the variables name. num now has the value of 89. When you type cast from double to int you drop off the decimal point from that number. No rounding happens when this is done.

Hope this helps you.
Boaz likes this