• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

? about cross platform compatibility

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for that explaination. That makes perfect sense. I should have thought of that.
Paul LaBrier
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic