Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Converting data in java

// Java Program to Illustrate Conversion of
// Integer and Double to Byte
 
// Main class
class GFG {
 
    // Main driver method
    public static void main(String args[])
    {
        // Declaring byte variable
        byte b;
 
        // Declaring and initializing integer and double
        int i = 257;
        double d = 323.142;
 
        // Display message
        System.out.println("Conversion of int to byte.");
 
        // i % 256
        b = (byte)i;
 
        // Print commands
        System.out.println("i = " + i + " b = " + b);
        System.out.println(
            "
Conversion of double to byte.");
 
        // d % 256
        b = (byte)d;
 
        // Print commands
        System.out.println("d = " + d + " b= " + b);
    }
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Converting #data #java
ADD COMMENT
Topic
Name
8+9 =