Data Types in Java

Haider Ali
Java by coding examples
Jan 19, 2024
public class P007_DataTypes
{
public static void main(String args[])
{
int aint;
float afloat;
double adouble;
boolean aboolean;

//aint=9999999999; Compilation error (number too large)
//afloat=8888888.888; error
aint=10;

afloat=2;
//afloat=2.5;
afloat=2.3f;
adouble=7777777.77;

//afloat=adouble; Error
afloat=(float) adouble;

adouble=afloat;

//aboolean=2; (incompatible type)
aboolean=false;

System.out.println("aint= " + aint +
" afloat=" + afloat +
" adouble=" + adouble +
" aboolean=" + aboolean);
}
}

Output:

aint= 10 afloat=7.7777776E7 adouble=7.7777776E7 aboolean=false

--

--