전체 글(37)
-
Coding Exercise 22: Perfect Number
What is the perfect number? A perfect number is a positive integer which is equal to the sum of its proper positive divisors. Proper positive divisors are positive integers that fully divide the perfect number without leaving a remainder and exclude the perfect number itself. For example, take the number 6: Its proper divisors are 1, 2, and 3 (since 6 is the value of the perfect number, it is ex..
2021.03.30 -
Coding Exercise 21: All Factors
Write a method named printFactors with one parameter of type int named number. If number is < 1, the method should print "Invalid Value". The method should print all factors of the number. A factor of a number is an integer which divides that number wholly (i.e. without leaving a remainder). For example, 3 is a factor of 6 because 3 fully divides 6 without leaving a remainder. In other words, 6 ..
2021.03.29 -
Coding Exercise 20: Greatest Common Divisor
Write a method named getGreatestCommonDivisor with two parameters of type int named first and second. If one of the parameters is < 10, the method should return -1 to indicate an invalid value. The method should return the greatest common divisor of the two numbmers (int). The greatest common divisor is the largest positive integer that can fully divide each of the integers (i.e. without leaving..
2021.03.21 -
Coding Exercise 19: Last Digit Checker
Write a method named hasSameLastDigit with three parameters of type int. Each number should be within the range of 10 (inclusive) - 1000 (inclusive). If one of the number is not within the range, the method should return false. The method should return true if at least two of the numbers share the same rightmost digit; otherwise, it should return false. public class LastDigitChecker { public sta..
2021.03.15 -
Coding Exercise 18: Shared Digit
Write a method named hasSharedDigit with two parameters of type int. Each number should be within the range of 10 (inclusive) - 99 (inclusive). If one of the numbers is not within the range, the method should return false. The method should return true if there is a digit that appears in both numbers, such as 2 in 12 and 23; otherwise, the method should return false. public class SharedDigit { p..
2021.03.14 -
Coding Exercise 17: Even Digit Sum
Write a method named getEvenDigitSum with one parameter of type int called number. The method should return the sum of the even digits within the number. If the number is negative, the method should return -1 to indicate an invalid value. public class EvenDigitSum { public static int getEvenDigitSum(int number){ if (number 0){ if (number % 2 == 0){ su..
2021.03.13