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.
- 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.
- If, array[] = {1,9,8,5,2};
- what is array length?
- what is array[2]?
14. What do the
following functions return for:
String x =
"hello";
String y =
"world";
a)
System.out.println(x + y);
b)
System.out.println(x.length());
c)
System.out.println(x.charAt(3));
d)
System.out.println(x.equals(y));
15. State the value
of characteristic and mantissa when the following code is executed.
String s =
"4.3756";
int n =
s.indexOf('.');
int
characteristic = Integer.parseInt(s.substring(0,n));
int mantissa =
Integer.valueOf(s.substring(n+1));
16. Write the
return type of the following library functions :
(i)
isLetterOrDigit(char)
(ii)
replace(char,char)
Section B
[Answer any four Questions]
1.
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.
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.
2.
Write a menu driven program to accept
a number and check and display whether it is a Prime number or not OR an
Automorphic number or not. (Use switch – case statement)
1. Prime number: A number is said to be a prime number if it is divisible
only by 1 and itself and not by any other number.
Example: 3, 5, 7, 11, 13 etc.
Example: 3, 5, 7, 11, 13 etc.
2. Automorphic number: An Automorphic number is the number which is
contained in the last digit(s) of its square.
Example 25 is an Automorphic number as its square i.e, 625 and 25 is present as the last two digits.
Example 25 is an Automorphic number as its square i.e, 625 and 25 is present as the last two digits.
3. Write a program to store 6 elements in an array P, and 4 elements in
an array Q and produce a third array R, containing all the elements of array P
and Q. Display the resultant array.
EXAMPLE INPUT
EXAMPLE INPUT
P[6]
|
Q[4]
|
OUTPUT R[10]
|
4
|
19
|
4
|
6
|
23
|
6
|
1
|
7
|
1
|
2
|
8
|
2
|
3
|
3
|
|
10
|
10
|
|
19
|
||
23
|
||
7
|
||
8
|
4.
Write a program to input an integer
array A[] of n size. Store all even
integers of array A[] from left to right
and all odd integers from right to left in another array B[]. Print both the
arrays.
Example :
If A[] = {3, 6, 9, 5, 12, 14, 8, 18, 7, 21, 10, 4} then,
B[] = {6, 12, 14, 8, 18, 10, 4,
21, 7, 5, 9, 3}
5.
Write two separate programs for
a)
Write a program to input a string and
print out the text with the uppercase and lowercase letters reversed, but all
other characters should remain the same as before. Example:
INPUT : WelComE TO school
OUTPUT : wELcOMe to SCHOOL
b)
Write a program to accept a word and
convert into lowercase if it is in uppercase, and display the new word by
replacing only the vowels with the character following it.
Example:
Sample
Input : computer
Sample
Output : cpmpvtfr
6.
Using the switch statement, write a
menu driven program to:
i. Generate and
display the first 10 terms of the Fibonacci series
0, 1, 1, 2, 3, 5, .....
The first two Fibonacci numbers are 0 and 1, and each subsequent
number is the sum of the previous two.
Ii To find the
smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be
displayed.
SOLVE THE QUESTIONS AND SUBMIT BY 25/06/2018
No comments:
Post a Comment