Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Casting here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Casting
- {
- public static void main (String[] args){
- //implicit casting
- byte i = 127;
- // No casting needed for below conversion
- short j = i;
- int k = j;
- long l = k;
- float m = l;
- double n = m;
- System.out.println("IMPLICIT");
- System.out.println("byte value : "+i);
- System.out.println("short value : "+j);
- System.out.println("int value : "+k);
- System.out.println("long value : "+l);
- System.out.println("float value : "+m);
- System.out.println("double value : "+n);
- //impl
- double a = 1175.55;
- // Explicit casting is needed for below conversion
- float b = (float) a;
- long c = (long) b;
- int d = (int) c;
- short e = (short) d;
- byte f = (byte) e;
- System.out.println("EXPLICIT");
- System.out.println("double value : "+a);
- System.out.println("float value : "+b);
- System.out.println("long value : "+c);
- System.out.println("int value : "+d);
- System.out.println("short value : "+e);
- System.out.println("byte value : "+f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement