Why are the default char, double and float values ​​printed like this?

I'm trying to find Why am I getting' ' when I print a char variable that has been initialized with a default value '\u0000'?

I also know that float and double have default values ​​of "0.0f" and "0.0d" , but here, when I print their default values, the suffix "f" and "d" are not printed. So why are these suffixes not printed with values?

Here is the code:

class Check{
    char c;
    float f;
    double d;

    public static void main(String a[]) {
        Check obj = new Check();
        System.out.println("Default value of char : " + obj.c);
        System.out.println("Default value of float : " + obj.f);
        System.out.println("Default value of double: " + obj.d);
    }
}

char ''. float "0.0", double - "0.0". , : '' '\ u0000' null ( - ) char? , float double, ? (, "0.0f" "0.0d" )

. : /, char?, , .

+4
3

java-, Socket.

"\ u" (java Unicode), char, .

character '\ u0000' null , : , ...

, -, "-" , EVEN THOUGH, .

+3

, :

  • "}", .

  • System.out.println(obj.c); // Without the String
    

    a '' d f , 0.0.

  • ascii , java- , , , , char, "\ u0000", "", float double values. , \n, , .

-2
public class Example {
    int i;
    static char c;
    static boolean b;
    static double d;

    public static void main (String args[]) {
        Example e = new Example();
        System.out.println(e.i);
        if (c==0 & c=='\u0000') {System.out.println(c + "null");}
        System.out.println(b);
        System.out.println(d);
        System.out.println(e.i);
        System.out.println(Example.c);
        System.out.println(Example.b);
        System.out.println(Example.d);
    }
}
-2
source

Source: https://habr.com/ru/post/1619618/


All Articles