Array, Function and Constructor
Full Marks: 70 Time: 1 Hour 45 min
Section A
Programming questions : 4 × 15 = 60
1. Write a program to create an array to store 10 elements and print
a. the largest number in the array
b. the smallest number in the array
c. the average of the numbers stored in the array
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
5. Write the differences between a constructor and a method. 2
6. What do you mean by call by value and call by reference? Give examples. 4
7. Why an array of float is not considered to a primitive data type? 2
8. What will be the output of the below code when n=145 2
int number(int n)
{
int s=0;
while(n>0)
{
s=s+n%10;
n/=10;
}
return n;
}