전체 글(37)
-
Coding Exercise 16: First And Last Digit Sum
Write a method named sumFirstAndLastDigit with one parameter of type int called number. The method needs to find the first and the last digit of the parameter number passed to the method, using a loop and return the sum of the first and the last digit of that number. If the number is negative then the method needs to return -1 to indicate an invalid value. public class FirstLastDigitSum { public..
2021.03.12 -
Coding Exercise 15: Number Palindrome
Write a method called isPalindrome with one int parameter called number. The method needs to return boolean. It should return true if the number is a palindrome number otherwise it should return false. public class NumberPalindrome { public static boolean isPalindrome(int number){ int reverse = 0; int i = number; while (i != 0) { reverse = (reverse * 10) + (i % 10); i /= 10; } return reverse == ..
2021.03.11 -
Coding Exercise 14: Sum Odd
Write a method calld isOdd with an int parameter and call it number. The method needs to return a boolean. Check that number is > 0, if it is not return false. If number is odd return true, otherwise return false. Write a second method called sumOdd that has 2 int parameter start and end, which represent a range of numbers. The method should use a for loop to sum all odd numbers in that range in..
2021.03.06 -
Coding Exercise 13: Number Of Days in Month
Write a method isLeapYearwith a parameter of type int named yaer. The parameter needs to be greater than or equal to 1 and less than or equal to 9999. If the parameter is not in that range return false. Otherwise, if it's in the valid range, calculate if the year is a leap year and return true if it is, otherwise, return false. A year is a leap year if it's divdisible by 4 but not by 100, or it'..
2021.03.03 -
Coding Exercise 12: Number in Word
Write a method called printNumberInWord. The method has one parameter number which is the whole number. The method needs to print "ZERO", "ONE", "TWO", ... "NINE", "OTHER" if the int parameter number is 0, 1, 2, ... 9 or other for any other number including negative numbers. You can use if-else statement or switch statement whatever is easier for you. public class NumberInWord { public static vo..
2021.03.03 -
Coding Exercise 11: Playing Cat
The cats spend most of the day playing. In particular, they play if the temperature is between 25 and 35 (inclusive). Unless it is summer, then the upper limit is 45 (inclusive) instead of 35. Write a method isCatPlaying that has 2 parameters. Method needs to return true if the cat is playing, otherwise return false. 1st parameter should be of type boolean and be named summer it represents if it..
2021.03.02