Feb 15, 2012

[Java] console output (println, print, printf)

\n  :  next line
\t  :  tab
\"  :  " (quotation mark)
\\  :  \ (backslash)

System.out.println("She said \"I love you.\" ");
     -->  She said "I love you."

System.out.print("I will");
System.out.print("get a job soon");
     -->  I will get a job soon


%d  :  Integer
%f  :  Real number
%e  :  Exponent
%c  :  Char
%s  :  String

System.out.printf("%d,  %f,  %e,  %c,  %s",  12, 3.44, 0.00223, 'S', "SHSJ");
     -->  12, 3.44, 2.23e-3,  S,  SHSJ

No comments:

Post a Comment