Friday, January 30, 2015

Typecasting in JAVA


Typecasting in JAVA
class Typecasting
{
   public static void main(String args[])
    {
      System.out.println("Variables created");
      char c='x';
      byte b=50;
      short s=1996;
      int i=123456789;
      long l=1234567654321L;
      float f=3.142F;
      double d=0.000000987;
      System.out.println("c= " +c);
      System.out.println("c= " +c);
      System.out.println("b= " +b);
      System.out.println("s= " +s);
      System.out.println("i= " +i);
      System.out.println("l= " +l);
      System.out.println("f= " +f);
      System.out.println("d= " +d);
      System.out.println(" ");
      System.out.println("Types converted");
      short s1=(short)b;
      short s2=(short)i;
      float n1=(float)l;
      int m1=(int)f;
      System.out.println("(short)b= " +s1);
      System.out.println("(short)i= " +s2);
      System.out.println("(floatt)l= " +n1);
      System.out.println("(int)f= " +m1);
     }
}
OUTPUT

0 comments:

Post a Comment

Blog Archive