• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

? about cross platform compatibility

 
Paul LaBrier
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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[])
throws java.io.IOException
{
exercise7dot8a();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8b();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8c();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8d();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8e();
}
[/CODE]
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
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul LaBrier
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for that explaination. That makes perfect sense. I should have thought of that.
Paul LaBrier
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course the example wouldn't work on Mac, so it isn't really platform independent.
The following, OTOH, should work everywhere:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic