Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

basic System.out.write Question  RSS feed

 
Satish Kumar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
when i execute the below program, this programs executes sucessfully and gives the o/p as expected
A
Press any key to continue . . .


class WriteDemo {
public static void main(String args[]) {
int b;
b='A';
System.out.write(b);
System.out.write('\n');
}
}

but when i comment out //System.out.write(b), the character 'A' is not printed on the console.
can any one give explanation on why it is not printing 'A'
 
Collins Mbianda
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!!
May be i don't get the sense of your question.
The line that print A is:
System.out.write(b);
If you comment it, the job will not be done.
The instruction will be ignored.

Can you explain the real problem ?
[ August 19, 2007: Message edited by: Collins Mbianda ]
 
Satish Kumar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh its actually commenting //System.out.write('\n');
on commenting this line i was unable to view the value of b
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out is a buffered print stream. You have to flush that stream before you exit, or you may lose characters.

Henry
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:
System.out is a buffered print stream. You have to flush that stream before you exit, or you may lose characters.


Which can be done by calling flush(), and also, close().
[ August 19, 2007: Message edited by: Red Smith ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!