Array, Function and Constructor
Array, Function and Constructor
Section A
Programming questions : 4 × 15 = 60
2. Write a program to that accepts integers from user and stores them in an array of
size 10 only if the number is a prime number.
3. Create a class Circle with three instance variables. Initialize the objects of the
class using constructor. Create another method called “area()” to calculate the
area of a triangle. Check whether the values entered can form a triangle or not
before calculating the area.
Note: Formula for calculating area of a triangle is as follows:
Area s(s a) 2 (s b) 2 (s c) 2 , where a, b, c are the sides of the triangle and s (a b c) / 2
4. Write a java class to calculate and print the electricity bill to be paid by a
customer.
Assume that the customer pays a rent of Rs. 250.00.
No. of units Charge per unit
Upto 100 units Rs. 1.50
For the next 100 units Rs. 2.00
For next 50 units Rs. 2.50
Beyond 250 units Rs. 4.00
Section B
6. What do you mean by call by value and call by reference? Give examples. 4