Preskoči na glavni sadržaj
Prijava
Sign up for FREE
arrow_back
Biblioteka

Arrays Test Part 2

star
star
star
star
star
Posljednje ažuriranje about 2 years ago
2 questions

ARRAY TEST FREE RESPONSE - A

The following Numbers class will be used to analyze and retrieve sets of numbers.

public class Numbers

{

/** @param num is a positive non-decimal value

* Precondition : num >= 0

* @return true if the sum of the digit divisors of num is odd

@return false if the sum of the digit divisors of num is even

*/

public static boolean isGoofy(int num)

{

/* to be implemented in part(a) */

}

/* @param count is a positive non-decimal value

* Precondition : count > 0

* @return an array containing count Goofy numbers

*/

public static int[] getSomeGoofyNumbers(int count)

{

/* to be implemented in part(b) */

}

// There may be variables / fields, constructors, and methods that are not shown.

}

1
Pitanje 1
1.

A. Write the Numbers method isGoofy(), as started below.  isGoofy() will receive an integer and determine if that integer is goofy or not goofy.

A goofy number is any number that has a sum of its digit divisors that is odd. The sum of the digit divisors must be greater than zero.

The number 12 has 2 digits – 1 and 2. The number 123 has 3 digits - 1,2, and 3.

The number 26 has 2 digits – 2 and 6. The number 26 is only divisible by 2.

The call isGoofy(12) would return true as 12 has a digit divisor sum of 3 – [1,2] which is odd.

The call isGoofy(15) would return false as 15 has a digit divisor sum of 6 – [1,5] which is even.

The call isGoofy(26) would return false as 26 has a digit divisor sum of 2 – [2] which is even. The call isGoofy(271) would return true as 271 has a digit divisor sum of 1 – [1] which is odd.

The call isGoofy(1234) would return true as 1234 has a digit divisor sum of 3 – [1,2] which is odd.

/** @param num is a positive non-decimal value

* Precondition : num >= 0

* @return true if the sum of the digits of num is odd

@return false if the sum of the digits of num is even

*/

public static boolean isGoofy(int num)

{

//code goes here

}

1
Pitanje 2
2.

B. Write the Numbers method getSomeGoofyNumbers(), as started below.  getSomeGoofyNumbers() will receive a count of how many Goofy numbers to return.

The call getSomeGoofyNumbers(3) would return [1, 3, 5].

The call getSomeGoofyNumbers(15) would

return [1, 3, 5, 7, 9, 10, 12, 13, 14, 16, 17, 18, 19, 21, 25].

You must call the method from part a, assuming the method works as specified regardless of what you wrote. /* @param count is a positive non-decimal value

* Precondition : stop > 0

* @return an array containing count Goofy numbers

*/

public static int[] getSomeGoofyNumbers(int count)

{

//code goes here

}