Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes ? about cross platform compatibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "? about cross platform compatibility" Watch "? about cross platform compatibility" New topic

? about cross platform compatibility

Paul LaBrier

Joined: Apr 08, 2002
Posts: 21
In order to get th output of a console app to pause and keep the results from scrolling off the screen I did the following.
public static void main(String args[])
System.out.print("\n\nPress ENTER to continue:");;
System.out.print("\n\nPress ENTER to continue:");;
System.out.print("\n\nPress ENTER to continue:");;
System.out.print("\n\nPress ENTER to continue:");;
When I compiled and executed it on a Sun Sparc20 running Solaris 7 it worked fine. When I tried it on Win98se it would only pause the first and third time. It would skip the second and fourth time. I recompiled it on Win98se and no change.
Does anyone have any ideas what causes this?
Paul LaBrier
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
The reason for this behaviour is because of different ways OS interprets "Enter" key. On Unix, it is <LF> (Line Feed); on DOS, it is <CR>+<LF>(Carriage Return + Line Feed) and on Macintosh, it is <CR>.
Check out the below program. It should work on both Windows and Unix though I have not tested it.

where 10 is the Ascii value of LF.

Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Paul LaBrier

Joined: Apr 08, 2002
Posts: 21
Thank you for that explaination. That makes perfect sense. I should have thought of that.
Paul LaBrier
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Of course the example wouldn't work on Mac, so it isn't really platform independent.
The following, OTOH, should work everywhere:

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: ? about cross platform compatibility
jQuery in Action, 3rd edition