Click here to watch in Youtube :
https://www.youtube.com/watch?v=5Qa40NrzajQ&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java Variable Type Conversion && Type Casting |
Java Tutorial : Java Variable Type Conversion && Type Casting |
Java Tutorial : Java Variable Type Conversion && Type Casting |
Java Tutorial : Java Variable Type Conversion && Type Casting |
public class TypeConversionDemo { public static void main(String[] args) { double doubleVariable; long longVariable; int intVariable = 10; /* * Variable of smaller capacity is be assigned to another variable of * bigger capacity. */ longVariable = intVariable; doubleVariable = intVariable; System.out.println("longVariable : " + longVariable); System.out.println("doubleVariable : " + doubleVariable); } } Output
longVariable : 10 doubleVariable : 10.0
public class TypeCastDemo { public static void main(String[] args) { double doubleVariable = 2898.9999; long longVariable = 199; int intVariable; /* * Variable of larger capacity is be assigned to another variable of * smaller capacity. */ intVariable = (int) longVariable; System.out.println("longVariable " + longVariable + " converted to intVariable : " + intVariable); intVariable = (int) doubleVariable; System.out.println("doubleVariable " + doubleVariable + " converted to intVariable : " + intVariable); } }
longVariable 199 converted to intVariable : 199 doubleVariable 2898.9999 converted to intVariable : 2898
https://sites.google.com/site/javaee4321/java/VariableDemoTypeConversionAndCastingApp.zip?attredirects=0&d=1
See also:
java online training
ReplyDeletejava training