Vous êtes sur la page 1sur 3

Section A

Question 1
(a) What is meant by a package? Name any two Java API packages
(b) What is a wrapper class? Give two examples
(c) What do you understand by 'Run Time' error? Explain with an example
(d) Differentiate between primitive data types and composite data types
(e) What is Polymorphism?
Question 2
(a) What is the return type of the following library functions:
    (i) isWhiteSpace( char )          (ii) replace(char, char)     
(b) Predict the output of the below code snippet:
int a = 345, b = 0;
a--;
b = a == 344 ? 3 : 44;
System.out.println("b = " + b);

(c) Transform the conditional statement of the above question into if else statement
if (a == 344)
b = 3;
else
b = 44;
(d) If int x = 5; find the value of the following expressions:
    (i) (5 * ++x) % 3    (ii) 'x' + 50
(e) Find the errors and correct them
int a= 10; b=15;
a = + b;
system.out.print( a);
(f) If String S = “ 2, 7, 4 , 5, 8’;
What is S.length()? What is S.indexOf(‘,’)?
Question 3
(a) Give the output of the following expressions
    (i) If x = 372.25, calculate Math.ceil(x);    (ii) If x = -4.5, calculate Math.abs(x);
(b) Given int a=5, Find the value of a after the execution of the statement
    a += a++ + --a + a*2
(c) Write a Java function to convert any data type to String data type
(d) Write a Java function that returns -1 if a searched character is not found
(e) If there are many return statements used within a function, how many will be executed and why?
(f) Write down Java expression for √(A 2 + B3 + C2)
(g) Write the output of the following program and also tell how many times the loop gets executed:
for (int a = 5; a <= 30; a += 5)
{
if (a % 3 == 0)
break;
else if (a % 5 == 0)
System.out.println(a);
continue;
}
(h) State the output of the following program segment:
String s1 = "67420";
String s2 = "character";
System.out.print(s1.substring(2));
System.out.print(" CHA" + s2.substring(0,3).toUpperCase());

(i) Convert the following for loop to corresponding while loop


int n = 5;
for (int a = 10; a >= 1; a--)
System.out.println(a * n);
(j) What will be the output when the following program segment is executed:
System.out.println("Doctor said \"An apple a day keeps the doctor away\" to me.");
(k) What will be the output when the following program segment is executed:
System.out.println(Character.isLetter('9'));

Section B
[Answer Any Four(4)]
Question 4
Define a class named MovieRating with the following description:
Data Members Purpose

int year To store the year of release of a movie

String title To store the title of the movie

float rating To store the popularity rating of the movie

Member Methods Purpose

MovieRating() Default constructor to initialize the data members

void input() To input and store year, title and rating

To display the title of the movie and a message based on the ratings
void display()
table given below
Ratings Table

Rating Message to be displayed

0.0 to 2.0 Flop

2.1 to 3.4 Semi-Hit

3.5 to 4.4 Hit

4.5 to 5.0 Super-Hit

Write a main method to create an object of the class and call the above member methods
Question 5
Design a class named Tom to overload a function TalkingTom() as follows:
1. void TalkingTom(String s1, String s2) with two string arguments and print the string which is greater in length.
2. void TalkingTom(String s) with one string argument and print the first and the last character of the string.
3. int TalkingTom(String s, char ch) with one string argument and one character argument and return the frequency of the
character argument in the given string
Write main method to call above member methods to display the output.
Question 6
Write a program to input a string and convert it into uppercase and print the pair of vowels and number of pair of
vowels occurring in the string.
Example:
Input:
"BEAUTIFUL BEAUTIES "
Output :
Pair of vowels: EA, AU, EA, AU, IE
No. of pair of vowels: 5
Question 7
Write a program to generate a triangle or an inverted triangle based upon User’s choice.
Example 1:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 1
Enter a word : BLUEJ
Sample Output:
B
LL
UUU
EEEE
JJJJJ
Example 2:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 2
Enter a word : BLUEJ
Sample Output:
BLUEJ
BLUE
BLU
BL
B
Question 8
Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.
Write a program to accept a word. Check and display whether the word is a palindrome or only a special word or
none of them.
Question 9
Write a program to accept a word. Remove duplicate letter from it and this display the new word.
Input : BOOK
Output: BOK

Vous aimerez peut-être aussi