Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Array, Function and Constructor

The document provides programming questions and instructions for creating an array, functions, and constructors in Java. It includes 4 questions - the first asks to create an array and print the largest, smallest, and average numbers; the second asks to store prime numbers in an array; the third asks to create a Circle class with a constructor and calculate the area of a triangle; the fourth asks to calculate an electricity bill based on usage. It also includes questions about the differences between constructors and methods, call by value vs reference, why arrays of floats are not primitive, and the output of a number function for an input.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Array, Function and Constructor

The document provides programming questions and instructions for creating an array, functions, and constructors in Java. It includes 4 questions - the first asks to create an array and print the largest, smallest, and average numbers; the second asks to store prime numbers in an array; the third asks to create a Circle class with a constructor and calculate the area of a triangle; the fourth asks to calculate an electricity bill based on usage. It also includes questions about the differences between constructors and methods, call by value vs reference, why arrays of floats are not primitive, and the output of a number function for an input.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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;
}

You might also like