Computer Practice Paper
Computer Practice Paper
4. Which of the following methods of Java return nearest and largest whole number which is
greater than or equal to the argument?
a. ceil b. floor c. trim d. max
5. Which of the below specifiers provide minimum security for the class members?
a. private b. protected c. public d. default/friendly access
6. _______variables are the variables declared inside a method and have a scope limited to the
method. They cannot be accessed outside the method.
a. Static b. local c. global d. protected
7. System.out.print(“Be happy, not because everything is good but because you can see the
good in everything”.substring(40).length());
a. 47 b. 46 c. 45 d. 40
9. Which of the following method can be used to convert String objects to integer objects?
a. toString() b. valueOf() c. Both (a) and (b) d. None of the above
1
10. Decide how many searches using linear search it will require to successfully search for 2
from the below array?
15 12 2 3 4 5
a. 2 b. 3 c. 4 d. 5
17. Which of the following statements are valid for a string declaration?
a. String d= null; b. String d= „null‟; c. String d=0; d. String d= (String) “Hello”;
18. Which of the following types of functions does not return a value?
a. Pure method b. Impure method c. Specific method d. None of these
19. ______fields may be accessed by all subclasses of the current class, but are not visible to
classes outside of the current package.
a. Public b. protected c. private d. default
20. Based on the below code snippet, conclude on the statement below it.
public class StopLight
{ int RedGreenYellow;
changeLight()
{ RedGreenYellow++
} }
The methods in a class definition are named, self-contained blocks of code that typically
operate on the fields that appear in the:
a. Object definition b. Interface definition c. Class definition d. Function definition
Question 2 [20]
a. Name the operators : a. < b. ++ c. && d. ?:
2. Write the following in Java expression: + +√
3. What does the token „keyword‟ refer to, in the context of Java? Give an example.
4. Write the difference between length and length() functions.
5. Write two characteristics of a constructor.
2
6. What is an array? Write a statement to declare an integer array of 10 elements.
7. How can a class type variable support the accessing of members of a class?
8. Write a statement each to perform the following task on a string:
a. Extract the second last character of a word stored in the variable wd.
b. Check if the second character of a string str is in upper case.
9. Define: Instance variables.
10. Give the output of the following program segment:
String say=”Pharaoh-meant-King”;
tring ok= say.substring(0,5).toLowerCase();
String wow=say.substring(5).toLowerCase();
System.out.println(“ok = “+ok);
System.out.println(“wow = “+wow);
Question 4 [15]
Write a program to accept the year of graduation from school as an integer value from the user.
Using the binary search technique on the sorted array of integers given below, output the
message "Record exists" if the value input is located in the array. If not, output the message
"Record does not exist".
Sample Input:
n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
1982 1987 1993 1996 1999 2003 2006 2007 2009 2010
Question 5 [15]
Define a class to accept and store 10 strings into the array and print the strings with even
number of characters.
Sample Input:
Enter Strings:
Apple
Cat
Book
Cake
Candle
Strings with even number of characters:
Book
Candle
3
Question 6 [15]
Define a class called BookFair with the following description:
Member
Purpose
Methods
void input( ) To input and store the name and price of the book
To calculate the price after discount. Discount is calculated as per the table
void calculate( )
given below
void display( ) To display the name and price of the book after discount
Price Discount
More than ₹1000 and less than or equal to ₹3000 10% of price
Write a main method to create an object of the class and call the above member methods.
Question 7 [15]
Write a program in Java to accept a word. Pass it to a function magic(String str). The function
checks the string for the presence of consecutive letters. If two letters are consecutive at any
position then the function prints "It is a magic string", otherwise it prints "It is not a magic
string".
Sample Input: computer
Sample Output: It is not a magic string
Sample Input: DELHI
Sample Output: It is a magic string
Question 8 [15]
A number is said to be Duck if the digit zero is (0) present in it. Write a program to accept a
number and check whether the number is Duck or not. The program displays the message
accordingly. (The number must not begin with zero)
Sample Input: 5063 Sample Input: 7453
Sample Output: It is a Duck number. Sample Output: It is not a Duck number.
**************************
4