📜  在java代码示例中转换数据

📅  最后修改于: 2022-03-11 14:52:12.146000             🧑  作者: Mango

代码示例1
// 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(
            "\nConversion of double to byte.");
 
        // d % 256
        b = (byte)d;
 
        // Print commands
        System.out.println("d = " + d + " b= " + b);
    }
}