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

 

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

Write a method that returns the number of pairs of corresponding elements in the two arrays contain a factor of the other number. For example, if 'first' was {4,8,22} and 'second' was {40,2,51} you would return 2 because 4 is a factor of 40 and 2 is a factor of 8, but 22 is not a factor of 51. Remember, you are only comparing the elements in the same position in each array, so the fact that 2 is also a factor of 4 does not matter. For this problem, we will consider a number to be a factor of itself, so if the same number appears in the same position in both arrays, that will count towards our total. If the lengths of 'first' and 'second' do not match, return a '-1' as an error code. As preconditions, you may assume that all the elements in both arrays are positive. Look at the test data for examples.


test2024_04_16_P1SLHL_countMults([17, 51, 101, 97, 65537], [59, 73, 404, 12, 256]) → 1
test2024_04_16_P1SLHL_countMults([15, 33, 71, 94], [45, 11, 52, 105]) → 2
test2024_04_16_P1SLHL_countMults([41, 77, 13, 500, 2], [7, 11, 13, 125, 19]) → 3

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

public int test2024_04_16_P1SLHL_countMults(int[] first, int[] second) { }

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

Copyright Nick Parlante 2017 - privacy