Forums Register Login

Thread.sleep alters the output!

+Pie Number of slices to send: Send
Hi,

I have got the below piece of code
When it's run it produces output line by line. I wonder why?




+Pie Number of slices to send: Send
Works perfectly on my computer. Produces the entire message on just a single line!
+Pie Number of slices to send: Send
What output does it produce?
+Pie Number of slices to send: Send
Read the method you are calling on System.out and see what it does. I shall remind you of the location of its API documentation: here. Look through that API page and you will find other methods; I think one with a rather similar name will help your problem.
+Pie Number of slices to send: Send
(OT: The program as written doesn't produce any output at all for me. Not sure why it would.)
+Pie Number of slices to send: Send
 

David Newton wrote:(OT: The program as written doesn't produce any output at all for me. Not sure why it would.)



Yes right. I think I moved a closing braces (unintentionally).

Even when that mistake is corrected there is no reason why the code should ever produce output on a new line :)
+Pie Number of slices to send: Send
 

David Newton wrote:(OT:



Ehh..what does OT stand for?
+Pie Number of slices to send: Send
Off-Topic
+Pie Number of slices to send: Send
Have I made a mistake and read println() when he said print()? If so, sorry for confusing everybody.
+Pie Number of slices to send: Send
Hi Sam,

How did you get it working? I tried it separately in a new class and still no use!


Without the sleep method it works fine.
+Pie Number of slices to send: Send
I don't see how that's possible; are you getting an exception?
+Pie Number of slices to send: Send

Interestingly, John's first code listing, and John's most recent code listing are not the same.

In the first listing, the sysout is in the catch block, and hence, won't print anything unless an exception is thrown. In the most recent listing, it should work.

Henry
+Pie Number of slices to send: Send
This is how the output comes:

*
*
*
W
e
l
c
o
m
e

t
o
.
.
. ....

strange
I don't get any exceptions.

+Pie Number of slices to send: Send
 

Henry Wong wrote:
Interestingly, John's first code listing, and John's most recent code listing are not the same.

In the first listing, the sysout is in the catch block, and hence, won't print anything unless an exception is thrown. In the most recent listing, it should work.

Henry



Yep I agree. That's all I did. Move the System.out.print(c); outside the catch. As Henry says this code should work fine.
What happens in your case? No output at all? You do need to wait for a couple of seconds before the output starts showing of course!

P:S -> The code you posted works fine. I did try it out once more with no changes at all:)
+Pie Number of slices to send: Send
 

john eipe wrote:This is how the output comes:

*
*
*
W
e
l
c
o
m
e

t
o
.
.
. ....

strange
I don't get any exceptions.



Nopes I get a straight line,
***Welcome to the MTH junior CAT***Press any key to continue . . .

Not sure why you are getting it on a different line .. Beats me!!
+Pie Number of slices to send: Send
When I ran this from Command Line it worked!
But when I try this in NetBeans I get the previous output. I tried resizing the Output window et all but to no use.
+Pie Number of slices to send: Send
I ran this in Netbeans with 100 millisec sleep time and it works. But if I increase it, gives the old one.
+Pie Number of slices to send: Send
Yep really strange! Probably something with the ide..Hard to say why though
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1114 times.
Similar Threads
prog of multiple inputs
Unix InputStream /n problem
Problem in println
Unicode value of char
System.out.print is printing 1 word in a single line?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:59:23.