Section A
[Answer all Questions]
1. Name the types
of error (syntax, runtime or logical error) in each case given below:
(i) Division by
a variable that contains a value of zero.
(ii)
Multiplication operator used when the operation should be division.
(iii) Missing
semicolon.
2. What is the
output of the following?
char c = 'A';
short m = 26;
int n = c+m;
System.out.println(n);
3. Write a
statement for each of the following:
a) Store a number
275 as a String
b) Convert the
String to a numeric value
c) Add it to the
existing total of 1000 to update the field
4. Give the output
of the following program segment:
double x = 2.9,
y = 2.5;
System.out.println(Math.min(Math.floor(x),
y));
System.out.println(Math.max(Math.ceil(x),
y));
5. Operators with
higher precedence are evaluated before operators with relatively lower
precedence. Arrange the operators given below in order of higher precedence to
lower precedence.(i) && (ii) % (iii) >= (iv) ++
6. Identify the
literals listed below:
(i) 0.5 (ii)
'A' (iii) false (iv) "a".
7. Explain, with
the help of an example, the purpose of default in a switch statement.
8.
Explain with an example, the if..else if construct.
9. Analyze the
following program segment and determine how many times the body of loop will be
executed (show the working).
x = 5; y = 50;
while(x<=y)
{
y=y/x;
System.out.println(y);
}
10. How many times
will the following loop execute? What value will be returned? [2]
int x = 2, y =
50;
do{
++x;
y-=x++;
}while(x<=10);
return y;
11. How many times
does the body of the loop gets executed?
for(int m=5;
m<=20; m+=5)
{
if(m%3 == 0)
break;
else
if(m%5 == 0)
System.out.println(m);
continue;
}
12. Analyze the
given program segment and answer the following questions
for(int
i=3;i<=4;i++)
{
for(int
j=2;j<i;j++)
{
System.out.print("
");
}
System.out.println("WIN");
}
i) How many
times does the inner loop execute?
ii) Write the
output of the program segment.
13.
If, array[] = {1,9,8,5,2};
(i)
what is array length?
(ii)
what is array[2]?
14. Differentiate
between public and private modifiers for members of a class.
15. Differentiate
between call by value or pass by value and call by reference or pass by
reference.
16. Write
Java statement to create an object mp4 of class digital.
17. If
a function contains several return statements, how many of them will be
executed?
18. Differentiate
between actual parameter and formal parameter.
19. What
is the use of exception handling in Java?
20. Write
the function prototype for the function “sum” that takes an integer variable
(x) as its argument and returns a value of float data type.
Section B
[Answer any four Questions]
1. Write
a program that outputs the result of the following evaluations based on the
number entered by the user.
• Natural logarithm of the number
• Absolute value of the number
• Square root of the number
• Random numbers between 0 and 1.
2. Write
a program using a function called area( ) to compute the area of a:-
• circle (π * r2) where π = 3. 14
• square (side * side)
• rectangle (length * breadth)
Display the
menu to output the area as per User’s choice.
3. Given
below is a hypothetical table showing rates of Income Tax for male citizens
below the age of 65 years:
Taxable Income (TI) in Income Tax in
Does exceed
1,60,000 Nil
Is greater
than 1, 60,000 & less than or equal to 5,00,000 (TI – 1,60,000) x 10%
Is greater
than 5,00,000 & less than or equal to 8,00,000 [(TI – 5,00,000) x 20%] + 34,000
Is greater
than 8,00,000 [(TI – 8,00,000) x 30%] +
94,000
Write a
program to input the age, gender (male or female) and Taxable Income of a
person.
If the age
is more than 65 years or the gender is female, display “wrong category”.
If the age
is less than or equal to 65 years and the gender is male, compute and display
the Income Tax payable as per the table given above.
4. Write
a program to perform binary search on a list of integers given below, to search
for an element input by the user, if it is found display the element along with
its position, otherwise display the message “Search element not found”
5,7,9,11,15,20,30,45,89,97
5. Design
a class to overload a function compare( ) as follows:
• void compare(int, int) – to compare
two integer values and print the greater of the two integers.
• void compare(char, char) – to
compare the numeric value of two characters and print the character with higher
numeric value.
• void compare (String, String) – to
compare the length of the two strings and print the longer of the two.
6. The
International Standard Book Number (ISBN) is a unique numeric book identifier
which is printed on every book. The ISBN is based upon a 10-digit code. The
ISBN is legal if 1*digit1 + 2*digit2 + 3*digit3 + 4*digit4 + 5*digit5 +
6*digit6 + 7*digit7 + 8*digit8 + 9*digit9 + 10*digit10 is divisible by 11.
Example: For
an ISBN 1401601499
Sum =1*1 +
2*4 + 3*0 + 4*1 + 5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253 which is divisible
by 11.
Write a
program to:
• Input the ISBN code as a 10-digit
number
• If the ISBN is not a 10-digit
number, output the message Illegal
ISBN and terminate the program
• If the number is 10-digit, extract
the digits of the number and compute the sum as explained above.
If the sum
is divisible by 11, output the message
Legal ISBN . If the sum is not divisible by 11, output the message Illegal ISBN .
To be Submitted by 3rd
July 2018
No comments:
Post a Comment