Write a program that convert one data type in to another data type

Category : Java | Sub Category : Data type, Variable and Arays | By Runner Dev Last updated: 2020-09-28 15:12:58 Viewed : 194


(Data type, Variable and Arays)

Write a program that convert one data type in to another data type

Description :In this program first make a class and write it main main method after initialize I, b, d. after we convert one data type in to another data type and print their value


Source Code:

/**

 *

 * Write a program that convert one data type in to another data type

 *

 */

Public class Conversion { // Declare class name

     public static void main(String args[]) { // daclre main line line of program main body of program start from here

           int i = 257; // Initialize and Declare i byte b; //initialize b

           double d = 323.42; // Initialize and Declare d

           System.out.println(" Conversion of int tom byte."); // print string line

           b = (byte) i; // convertion of data type

           System.out.println(" i and b is " + i + " " + b); // print value of I and b

           System.out.println(" Conversion od double to int "); // print string line

           i = (int) d; // convertion of data type

           System.out.println("d and i " + i + " " + d); // print value of I and d

           System.out.println(" Conversion of double to byte"); // print string line

           b = (byte) d; // convert value of b in to byte

           System.out.println("d and b " + d + " " + b); // print value of d and b

     } // end of main program

} // end of class


Output:



Search
Related Articles

Leave a Comment: