The output of the first Java program is incorrect

Sorry for the really stupid question, I'm learning a new language and take this code:

public class Exercise01 {
    int i;
    char c;

    public static void main(String[] args) {

        Exercise01 E = new Exercise01();
        System.out.println("i = " + E.i);
        System.out.println("c = [" + E.c + "]");
    }
}
/* Output:
i = 0
c = [
*/

Why doesn't the output create the "] character? Is it somehow related to Unicode?

PostEdited: Ec was not initialized for experimental purposes.

+5
source share
6 answers

You are trying to print a null character, since yours char cdoes not need to be initialized. those. \0Interestingly, you cannot easily copy and paste this character, since most C codes perceive this as the end of a line marker.

I see ]when I run the code.

Try changing your code with

char c = '?';

gives me a conclusion

i = 0
c = [?]

One way to reproduce this problem is to run on unix

java Main | more

i = 0
c = [
+4

, , , , U + 0000, E.c.

.

E.c .

+6

, , E.c

+1

, , c \0, .. " ". , println ]

+1

char C, int i. : !

0

All Articles