ICP Programming Assignment VI
ICP Programming Assignment VI
Programming Assignment-VI
(Methods)
1. Design a Simple Calculator using methods in java containing the following functionalities,
namely, with Addition, Subtraction, Multiplication, Remainder, Division and Square Root. The
signature of the methods are given below.
2. A pentagonal number is defined as n(3n–1)/2 for n = 1, 2, . . ., and so on. Therefore, the first
few numbers are 1, 5, 12, 22, . . . .
Write a method with the following header that returns a pentagonal number:
Write a java program that uses this method to display the first 100 pentagonal numbers with 10
numbers on each line.
4. Write a method that returns the number of days in a year using the following header:
Write a java program that displays the number of days in year from 2000 to 2020.
5. Write a method to test whether a number is prime or not using the following header.
Write a java program by using the above method to find the number of prime numbers less than
10000.
For example, 131 is a prime and also a palindromic prime, as are 313 and 757. Write a java
program using method that displays the first 100 palindromic prime numbers. Display 10
numbers per line, separated by exactly one space, as follows:
7. Twin primes are a pair of prime numbers that differ by 2. For example, 3 and 5 are twin primes,
5 and 7 are twin primes, and 11 and 13 are twin primes.
Write a java program using method to find all twin primes less than 1,000. Display the output as
follows:
(3, 5)
(5, 7)
...
...
8. A regular polygon is an n-sided polygon in which all sides are of the same length and all angles
have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for
computing the area of a regular polygon is
𝑛 × 𝑠2
𝐴𝑟𝑒𝑎 = 𝜋
4 × tan(𝑛 )
Write a method that returns the area of a regular polygon using the following header:
9. Given the two fractions a/b and c/d, write a java program using method that will compute their
sum in terms of the smallest common denominator.
10. Write a method that prints characters using the following header:
This method prints the characters between ch1 and ch2 with the specified numbers per line.
Write a java program that prints ten characters per line from 1 to Z. Characters are separated by
exactly one space.
11. Write a method that finds the number of occurrences of a specified character in a string using
the following header:
12. Write java method called count accepts a string as input and returns the number of vowels in it.
13. Write a java method to check a string is palindrome or not.
14. Some websites impose certain rules for passwords. Write a method that checks whether a string
is a valid password. Suppose the password rules are as follows:
Write a program that prompts the user to enter a password and displays Valid Password if the
rules are followed or Invalid Password otherwise.
15. Write a java program to calculate the area of triangle, square, circle, rectangle by using method
overloading.
*******************