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

 

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

Write a method that accepts two integers, 'num1' and 'num2', and returns an integer made up of the SUM of the digits that are the same in the same place-value location in the two numbers. You may assume that 'num1'>0 and 'num2'>0. For example, 27483 and 57893 both have a 7 in the 1000's place and both have a 3 in the one's place. For this reason, you will return 10 (7+3). In some cases, none of the digits will match, such as 782414 and 84172. These numbers DO share some digits, but not in the same place-value locations, so you would return 0. These two numbers: 5178300 and 51783 have no digits in common in the same place-value locations. Yes, they have all the same digits, but they are NOT in the same place-value locations, so you would return 0. Look at the test data for more examples. Note: I suppose you COULD do this recursively, but recursion is NOT required on this problem.


test2023_06_01_APP1SL_numDigSame(5, 7) → 0
test2023_06_01_APP1SL_numDigSame(248, 742) → 4
test2023_06_01_APP1SL_numDigSame(1234567, 1234567) → 28

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

public int test2023_06_01_APP1SL_numDigSame(int num1, int num2) { }

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: 230

Copyright Nick Parlante 2017 - privacy