• Post Reply Bookmark Topic Watch Topic
  • New Topic

.length for ones tens hundreds 'place'  RSS feed

 
Kyra Jenkins
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, anyone who can help me how to display the corresponding place value of the entered 3 digit number using .length?
Like if I enter 126, it would appear like,
1 hundreds
2 tens
6 ones

Thanks in advance.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

There is a standard way to use the / and % operators to get individual digits from a number. Note that number will probably be an int, and that is a primitive, and primitives don't have fields or methods. You cannot writeOut of that code, the only line that doesn't have a compiler error in is line 1. As I said, try the % and / operators and see what happens.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!