12-RE4-C10-COMQP
12-RE4-C10-COMQP
(iii) Which data type is greater than byte and less than int in size?
(a) double (b) char (c)float (d) boolean
Question 2
(i) Name the keyword that: [2]
(a) skips the current iteration but goes for the next iteration
(b) terminates the loop
(ii) What's the final answer stored in z in the following? [2]
z=Math.floor(Math.abs(-23.8));(2)
(iii) Write the Java expression for the following: [2]
(a) X+Y/(XY)²
(b) √x¹⁰+√mnc +|log x|
(iv) Create an object namely lily for the class Flower [2]
(v) Convert the following into while loop and also find the output [2]
for (x=6, y=3: x<=10;x+=2)
System.out.println(x+2*y);
System.out.println(x++);
(vi) Find the output for the following [2]
for(i=5;i<=8;i++)
for(j=1;j<=3;j++)
System.out.println(j);
System.out.println(i);
(vii) How many times the following loop gets executed? Find the output also. [2]
int a=6;
while(a++<=10)
{
System.out.println(++a);
System. out.println (a++);
}
System.out.println(++a);
(viii) Give TWO differences each between [2]
(a) Functions and constructors
(b) Pure and impure functions
(ix) Give the function prototype for a function namely add () that accepts 3 numbers and returns a boolean value.
What is its function signature [2]
(x) Convert the following into if else statement: [2]
ans= (x>y)?(x>15? Math.ceil(x):Math.floor(y)):Math.random();
Find the output also if x is 2 and y is 3
Question 3 [15]
Write a menu driven class to accept a number from the user and check whether it is a Pronic number or an
abundant number:
(a) Pronic number— eg: 6 (2x3=6), 20(4x5=20)
Multiplying the successive numbers result the input number
(b) Abundant number— (a number is called abundant if it is greater than greater the sum of its factors other
than the number itself)
Example: 18 is an abundant number. Its factors are 1+2+3+6+9 = 21 which is greater than 18.
Question 4 [15]
Define a class named Bank with the following description:
Instance variables/data members:
int P — To store the Principal
double T — To store the number of years
double R— To store the rate of interest
double SI - to calculate the simple interest
int age - to accept the age of the person.
Member methods:
void input( ) — To input and store the Principal and number of years
void calculate( ) — To compute the simple interest based on the rate of interest given below
No of years Interest
1 to 2 7%
Above 2. 8%
Question 5 [15]
Using function overloading:
(i) void calculate(int) - checks whether the number is a spy number or not
Eg: 123 is a spy number
Reason: 1+2+3 =6 and 1x2x3=6
(ii) String calculate (int a, int b) - checks whether any prime number is between a and b including these two
numbers.
Eg: a=6, b=10 then it should return the message, "Yes, there is a prime number"
a=8, b=10. It should return, "There is no prime number"
Question 6 [15]
Write a program to calculate the value of z for the following:
z = 2y/4! + 4y/6! + 6y/8! + .....ny/(n+2)!
Data members
int - y and n
double - z
Member Methods
Summation () - a default constructor
input() - accepts the value for y and n using scanner class
calc() - calculates the answer for z
display () - prints z
main() - call the above functions using object
Question 7 [15]
Write a program using function overloading to print the following patterns:
(a) void pattern (int) to do the following pattern by accepting the number of rows.
Example: if n= 5. (5 rows) then
1
12
123
1234
12345
(b) void pattern ( String) - accepts a string and prints and pattern as follows
Example: if the string is Lion, then it has to print as follows
L
LI
LIO
LION
Question 8 [15]
Write a program to accept two numbers a and b and print the:
(i) prime numbers between them.
(ii) print the tables between them