Lab 4 (Methods)
Lab 4 (Methods)
Lab 4 (Methods)
10. Write a Java method to print characters between two characters (i.e. A to P ).
Note: Prints 20 characters per line
Expected Output:
()*+,-./0123456789:;
<=>?@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_`abc
defghijklmnopqrstuvw
xyz
11. Write a Java method to check whether a year (integer) entered by the user is a leap year or not.
Expected Output:
Input a year: 2017
false
15. Write a Java method to find all twin prime numbers less than 100.
Expected Output: (define a method to check if a number is prime or not)
(3, 5)
(5, 7)
(11, 13)
(17, 19)
(29, 31)
(41, 43)
(59, 61)
(71, 73)
16. Write a method that takes an integer as argument and checks if the number is palindrome or
not. The method should return true if the number is palindrome or false if not. Write a main
method to check the method you have created.
17. Write a method named operation that takes two integer arguments and a char argument,
perform the calculation as per the char argument, and return the result:
Example: operation(2,5,’+’) should return 10 as result.
18. Write a program that uses the function power() to raise a number m to power n. The function
takes integer values for m and n and returns the result correctly. Use a default value of 2 for n to
make the function calculate squares when this argument is omitted. Write a function main() to
pass the value of m and n and display the calculated result.
19. Write a method that reverses the string passed as argument.
20. Write a method that replaces all the vowels of a string passed as argument with the next
character.
21. Write a method that accepts two strings as an argument, str1 and str2, and checks whether if
str2 is substring of str1 or not.
22. Write the definition of different methods as utility function for array as
a. a method to add item into array at last
b. a method to add item into array at position specified by user
c. a method to remove an item from last of array
d. a method to remove an item for the position specified by user
e. a method to remove an item specified by user, return false if the item is not found.
f. a method to return the size of an array.
g. a method to display all the items in array.
h. a method to return the item from index specified by user.
i. a method to return the index of item specified by user, return -1 if the item is not found.
j. a method to check if array is empty.
k. a method to check if array is full.
l. a method to replace occurrence of old item by new item, both specified by user.