jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Better way than this one? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Better way than this one?" Watch "Better way than this one?" New topic
Author

Better way than this one?

JJosshh xpto
Greenhorn

Joined: Oct 27, 2005
Posts: 1
Hello everyone.

Simple question.
Someone insert a numer like e.g 123
the output is 3 (number of digits)
Is there any easy way to do that instead of this :

System.out.print ( "insert number: ");
int number = Integer.parseInt(br.readLine().trim());

int count = 0;
while(number >0){
int digit= number%10;
number /=10;
if(number >= 0) count++;
}
System.out.print(count);

I know there's a better way to do this , like with a for- loop or something.
I'm getting a "blank" , can't remember .

Thanks a lot.

Josh
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
System.out.println(br.readLine().trim().length());


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Better way than this one?
 
Similar Threads
Extracting numbers from from a user input and comparing it to
how to get this output
a simple counter 1 to 100
cant get counters to work correctly
Update an array