• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

basic System.out.write Question  RSS feed

 
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'
 
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
 
author
Posts: 23832
140
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
 
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 ]
 
Whatever you say buddy! And I believe this tiny ad too:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!