Click here to watch in Youtube :
https://www.youtube.com/watch?v=6GriFQkmhB4&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java Variable Type Casting |
Java Tutorial : Java Variable Type Casting |
Java Tutorial : Java Variable Type Casting |
Java Tutorial : Java Variable Type Casting |
Java Tutorial : Java Variable Type Casting |
public class TypeConversionDemo { public static void main(String[] args) { int intVar = 200; /* * Variable of smaller capacity is be assigned to another variable of * bigger capacity. */ long longVar = intVar; // no explicit type casting required float floatVar = longVar; // no explicit type casting required System.out.println("Int value : " + intVar); System.out.println("Long value : " + longVar); System.out.println("Float value : " + floatVar); } }Output
Int value : 200 Long value : 200 Float value : 200.0
public class TypeCastDemo { public static void main(String[] args) { double doubleVar = 200000.04; /* * Variable of larger capacity is be assigned to another variable of * smaller capacity. */ int intVar = (int) doubleVar; // explicit type casting required byte byteVar = (byte) intVar; // explicit type casting required System.out.println("double value " + doubleVar); System.out.println("int value " + intVar); System.out.println("byte value " + byteVar); } }
double value 200000.04 int value 200000 byte value 64
https://sites.google.com/site/javaee4321/java/VariableDemoTypeCastApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment