id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2020_12_10_P1SLHL_HarshadNiven
prev  |  next  |  chance

Write a method that returns 'true' if the input parameter is a Harshad/Niven number and 'false' otherwise. HARSHAD/NIVEN NUMBER: A number that is divisible by the sum of its own digits. For example, 1729 is a Harshad number because 1 + 7 + 2 + 9 = 19 and 1729 = 19 × 91. More generally, a Harshad number, or Niven number in a given number base, is an integer that is divisible by the sum of its digits when written in that base. 2620 and 2924 are Harshad amicable pairs, since 2620 is divisible by (2 + 6 + 2 + 0) or 10, and 2924 is divisible by (2 + 9 + 2 + 4) or 17, since 2924 = 17 x 172.


test2020_12_10_P1SLHL_HarshadNiven(1729) → true
test2020_12_10_P1SLHL_HarshadNiven(645377) → false
test2020_12_10_P1SLHL_HarshadNiven(7363) → false

...Save, Compile, Run (ctrl-enter)

public boolean test2020_12_10_P1SLHL_HarshadNiven(int num) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 220

Copyright Nick Parlante 2017 - privacy