File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Better way than this one?" Watch "Better way than this one?" New topic

Better way than this one?

JJosshh xpto

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++;

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.

Joanne Neal

Joined: Aug 05, 2005
Posts: 3742

I agree. Here's the link:
subject: Better way than this one?