Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Better way than this one?

 
JJosshh xpto
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(br.readLine().trim().length());
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic