Scala: How do I make those codes more simple? -
how make following codes more simple? quite new scala. in advance!
example 1:
def xsum(n: int): int = { if (n<10) n else n%10+xsum(n/10) }
example 2:
def num(n: int): int = { if (xsum(n)%10==0) n else (100-xsum(n))%10 + n*10 } def xsum(n: int): int = { if (n<10) n else n%10 + xsum(n/10) }
example 3:
def tru(n: int): boolean = { n==0 || xsum(n)%10==0 } def xsum(n: int): int = { if (n<10) n else n%10 + xsum(n/10) }
def xsum(n:int):int= n.tostring.map(_-'0').sum
Comments
Post a Comment