Originally posted by Anand Iyer:
I tried..
char c=10;
System.out.println(c);
well.. the program compiled without error..
But when it printed out it was blank..
Why?Could anyone help me with this?
Thanks,
Anand
Hi Anand,
As you may know
char a=65;
System.out.println("Result = " + a);
gives you
Result = A
Means the charactor value corresponding to 65 is 'A' is printed.
If you code like this :
char c=10;
System.out.println(c);
The result will be the charactor value corresponding to 10 which "the new line character".
The new line charactor is the one which when tried to print works as '\n' in
System.out.println("This is for
testing. \n Hello");
So your result will be "The current line is skipped ".
To make more clear : I tried this Code
public static void main(
String args[]){
char a=65;
System.out.println("Result = " + a);
System.out.println("\nThis is for testing. \n Hello\n");
char ch=10;
System.out.println("This is for testing. "+ch+"Hello"+
"
Java is cool"+ch+ " Yep You Got it");
}
The result was :
Result = A
This is for testing.
Hello
This is for testing.
Hello Java is cool
Yep You Got it