• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reality Check  RSS feed

 
Barry Burd
Author
Ranch Hand
Posts: 133
10
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returning to a question that I posted a while ago (see http://www.coderanch.com/t/276466/Streams/java/IO-Tiger is there any "scanf"-like feature in Java beta SKD 1.5? In particular, is there a way to input say, an int value, with just one or two lines of code? [Is there a scanf("%d", n) or maybe a getInt() that takes keyboard input?]
I wouldn't ask this question a second time except that
- I have to write about the new beta, and not put my foot in my mouth,
- I can't do an exhaustive search to make sure that such a feature is not included.
Thanks
[ February 06, 2004: Message edited by: Jim Yingst ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's the new java.util.Scanner class. Not quite as compact as scanf would've been, but that's mostly because since Java doesn't have pointers, we can't just pass a bunch of pointers to primitives to some method and say "fill the values in for these". I think the biggest benefit to this class is the create() methods which make it relatively easy to start parsing a wider variety of input sources, including java.nio classes that previously would've required more thought to figure out how to access correctly.
On a sorta-related note, don't overlook the printf method added to PrintWriter and PrintStream, and the related java.util.Formatter class. While scanf is only partly implemented, we do now seem to have a pretty solid printf replacement.
[ February 06, 2004: Message edited by: Jim Yingst ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!