Example Program (JAVA data types)
by Rodelio Barcenas
/* This is a program which shows how to use the different data types. Primitive Data-types int -> Integer char -> Character Numeric Data-types float 32bit double 64bit Referenced Data-types arrays Strings */ public class datatype { public static void main(String arg[]) { int a,b,c; float x,y,z; double d,e,f; /* Integer Mode of Operation */
a = 5; b = 10; c = a + b; System.out.println("c = " + (a+b)); /* Float and Double Operation */ y = 1; z = 3; x = y / z; d = y / z; System.out.println(x); System.out.println(d); /* Type Casting of Variables (changing one data-type to another directly) */
a = 1; b = 3;
x = (float)(a) / (float)(b); d = (float)a / (float)b; System.out.println(x); System.out.println(d); } } NOTE: the keyword (float) attempts to convert a primitive datatype to a float value. The variable (a) will not become an integer
when type casted. Variable (a) has become a float equivalent
during the time it was type casted, but eventually does not
change its original data type declaration.
|