Monday, October 15, 2012

Java all data types example


package javaapplication2 ;

import java.util.Date;

  /**
 *
 * @author ASHISH SINGH
 */
class JavaDataType
  {

    public static void main(String[] args)
    {
                //Byte example
                
                 byte b1 = 100;
                 byte b2 = 20;
                
                System.out.println("Value of byte variable b1 is :" + b1);
                System.out.println("Value of byte variable b1 is :" + b2);

                //Charecter Example
               
        char ch1 = 'a';
                char ch2 = 65; /* ASCII code of 'A'*/
              
                System.out.println("Value of char variable ch1 is :" + ch1);  
                System.out.println("Value of char variable ch2 is :" + ch2);     


        //Double example
       
        double d = 1232.44;
                System.out.println("Value of double variable d is :" + d);

        //Float example
       
        float f = 10.4f;
                System.out.println("Value of float variable f is :" + f);

        //Integer example

         int i = 0;
                 int j = 100;
                 System.out.println("Value of int variable i is :" + i);
                 System.out.println("Value of int variable j is :" + j);

        //Long example

        long timeInMilliseconds = new Date().getTime();
                System.out.println("Time in milliseconds is : " + timeInMilliseconds);     

            //Short example

         short s1 = 50;
                 short s2 = 42;
                System.out.println("Value of short variable b1 is :" + s1);
                System.out.println("Value of short variable b1 is :" + s2);

               //Integer to string conversion

       
                i = 11;
                String str = Integer.toString(i);
        System.out.println("int to String : " + i);
          
    }
}


Output

 

No comments:

Post a Comment