The Artima Developer Community
Sponsored Link

Programming in Scala Forum
decimals

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Stefan Wagner

Posts: 1
Nickname: unknown
Registered: Oct, 2010

decimals Posted: Oct 20, 2010 4:15 AM
Reply to this message Reply
Advertisement
Programming in scala, Page 459, above Listing 20.12:

decimals is wrong / stackoverflows (and why private?)
private def decimals (n: Long): Int =
if (n == 1) 0 else 1 + decimals (n / 10)
// test it:
assert (decimals (7L) == 1)

def decimals (n: Long): Int =
if (n < 10) 1 else 1 + decimals (n / 10)

Topic: page 241, compile error (pre-print version of the 2nd edition) Previous Topic   Next Topic Topic: java program help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use