Variables and Datatypes

Datatype Table

DatatypeSizeRange
Int4 Bytes-2147483648 … +2147483647
Boolean1 bittrue or false
Byte1 Byte(8 bit)-127…+127
short2 bytes-32.768 – 32.767
long8 Bytes-9,223..*10E18….+9,223*10E18
float4 Bytes-+3.410E38
double8 Bytes-+ 1.7e+038
char2 Bytes0 … 65,536

Example

int number = 10;

float num2 = 10f; // dont forget f after the value, otherswise it will not be considered as float

char text = ‘a’;

char s = 76; // L in ASCII = 76 ,A = 65 ,Z = 90

boolean change = true;

Output:

10
10.0
a
L
true

Typecasting example:

int a = 2;
float testnum = 9.2f;
double myDouble = a; // automated cast to int ,output 2
int res = (int)testnum; // cast to int,output 9

Leave a Reply

Your email address will not be published. Required fields are marked *