• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A problem determining the length of an int variable converted to a string..........

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a program whereby I'm accepting input form the keyboard, converting it to a String, and then displaying it.
Firstly however, I want to check whether the inputted value comprises more than 1 charcater or not.
I've done the following :-

In other words, if I enter the value '22' at the keyboard, because it comprises of more than one digit, i want the program to print "two digits present!".
But it doesn't work - nothing happens.
What am I doing wrong here?
[ December 23, 2002: Message edited by: Marilyn de Queiroz ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
args is an array with all command line arguments (however many there are). args[0] is the String representing the first argument (if there is one). So you want to look at args[0].length() rather than args.length. Of course, make sure args.length > 0 before trying to access args[0].
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are differences b/w: length and length(), i modified your prog, hope it will help you understand better.

[ December 23, 2002: Message edited by: Marilyn de Queiroz ]
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's one of several possible ways of getting a count of the digits in an integer.

[ December 22, 2002: Message edited by: Michael Matola ]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Cattle Drive...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic