Batch11 Task
Batch11 Task
Define a Method that checks for whether a given input is a palindrome number or
not, and return a string.
Write the method with following specifications
Name of method: checkPalindrome
Arguments: 1 Integer Argument
Return Type: A String value
Value must not be negative. If yes, then return -1 as string.
Value must not be from 0 to 9. If yes, then return -2 as string.
If value is a palindrome, then return true as string otherwise return false as
string.
Program-22
Define a method which accepts a 4-digit value as number and checks whether the
number is armstrong or not.
Armstrong number: An Armstrong number is an n-digit number that is equal to the sum
of the nth powers of its digits.
For this program we need 4-digit armstrong number and is calculated as
Input: 1634 is a 4-digit armstrong number defined as
1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634
Write the method with the following specifications:
Name of method: checkArmStrong() // which accepts an integer value as argument and
return the String as specified below.
Arguments: one argument of type integer
Return Type: a String value
Specifications: The value returned by the method checkArmStrong() is determined by
the following rules:
If the input value is negative, return "-1" as string.
If the input value is not a 4-digit number, return "-2" as string.
Program-24
Define a method which accepts an integer value as argument and return the factors
of the given value.
Write the method with the following specifications:
Name of method getFactors() // which accepts an integer value as argument and
return a String.
Arguments: one argument of type integer
Return Type: String value
Input: 28
Output: "1 2 4 71 142 284"
Input: -20
Output: "-1"
Input: 0
Output: "-2"
Specifications: The value returned by the method getFactors() is determined by the
following rules:
1) If the value is negative, return "-1" as string
2) If the value is zero, return "-2" as string
3) In other case, return the string, concatenating all the factors of the given
number separating each factor with a blank space.
Program-25
Define a method which accepts a value as number and returns the sum of factors of
the value.
Write the method with the following specifications:
Name of method getSumOfFactors() // which accepts an integer value as argument and
return a String.
Arguments: one argument of type integer
Return Type: integer value
Specifications: The value returned by the method getSumOfFactors() is determined by
the following rules:
Value must not be negative. If yes, then return -1
Value must not be 0. If yes, then return -2.
Program-26
Define a method which accepts 2 values as number and returns the even numbers
between the 2 values.
Write the method with the following specifications
Name of method getEvenNumbers() // which accepts 2 integer values as arguments and
return the even numbers between the range.
Arguments: Two arguments of type integer
Return Type: String value
Note: If the first argument value is greater than second value, generate even
numbers from first value to second value. If the second value is less than first
value, generate even numbers from second value to first.
Specifications: The value returned by the method getEvenNumbers() is determined by
the following rules
Values must not be negative. If yes, then return -1 as string.
The values must be returned as a single string where each value is separated by a
single blank space.
For Example:
Input: 10 20
Output: 10 12 14 16 18 20
Input: 20 10
Output: 10 12 14 16 18 20