GeeCON Prague 2014*
The moose likes Cattle Drive and the fly likes A problem determining the length of an int variable converted to a string.......... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "A problem determining the length of an int variable converted to a string.........." Watch "A problem determining the length of an int variable converted to a string.........." New topic
Author

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

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
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 ]

John Bonham was stronger, but Keith Moon was faster.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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].


"I'm not back." - Bill Harding, Twister
Thana Bujakorn
Greenhorn

Joined: Dec 18, 2002
Posts: 12
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 ]
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1747
    
    2
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
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Moving to Cattle Drive...
 
GeeCON Prague 2014
 
subject: A problem determining the length of an int variable converted to a string..........