861-22-1
861-22-1
861-22-1
SAMPLE PAPER - 1
COMPUTER APPLICATIONS
Maximum Marks: 50
Time allowed: One and a half hours
Answers to this Paper must be written on the paper provided separately.
You will not be allowed to write during the first 10 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this Paper is the time allowed for writing the answers.
Attempt all questions from Section A and any four questions from Section B.
SECTION A
(Attempt all questions.)
Question 7.
Write a program in Java to enter a String/Sentence and display the longest word and the length of the
longest word present in the String.
Sample Input: “SOURAV GANGULY IS THE PRESIDENT OF BCCI”
Sample Output: The longest word: PRESIDENT: The length of the word: 9
Answers
Section-A
Answer 1.
(i) (d) Number
Explanation :
Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.
(ii) (b) Strings in java are mutable
Explanation :
Strings in Java are immutable that is they can not be modified.
(iii) (d) IlikeJava
Explanation :
Java defines an operator +, it is used to concatenate strings.
(iv) (b) Character
Explanation :
In Java Character is wrapper class for char type.
(v) (c) Both (a) and (b)
Explanation :
In java, non static functions can access both static data members and non static data members.
(vi) (d) FESTIVAL
Explanation :
str.substring(4,12) retunrs characters from index 4 to 11 , that is “Festival” and toUpperCase() converts
it to FESTIVAL.
(vii) (d) Encapsulation
Explanation :
It is a way of combining both data members and member functions, which operate on those data
members, into a single unit. We call it a class in OOPs generally.
(viii) (a) Private
Explanation :
The Private access specifier is most strict as private members can be accessed only in the class where
they are defined.
(ix) (b) Primitive data type and an object of a wrapper class
Explanation :
Here the variable x is of primitive data type. Whereas Integer y is an object of Integer wrapper class.
(x) (a) True
Explanation :
Unlike the other wrappers Void class doesn’t store a value of type void in itself and hence is not a
wrapper in true essence. - The Void class according to javadoc exists because of the fact that some time
we may need to represent the void keyword as an object.
Section-B
Answer 2.
import java.util.Scanner;
public class Temperature
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
double arr[] = new double[20];
Answer 5.
import java.util.Scanner;
public class NameInitials
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter a name of 3 or more words:”);
String str = in.nextLine();
int len = str.length();
System.out.print(str.charAt(0) + “ “);
for (int i = 1; i < len; i++)
{
char ch = str.charAt(i);
if (ch == ‘ ‘)
{
char ch2 = str.charAt(i + 1);
System.out.print(ch2 + “ “);
}
}
}
}
Answer 6.
import java.util.Scanner;
public class SurnameFirst
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter a name of 3 words:”);
String name = in.nextLine();
int lastSpaceIdx = name.lastIndexOf(‘ ‘);
System.out.println(surname + “ “ + initialName);
}
}
Answer 7.
import java.util.Scanner;
public class LongestWord
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter a word or sentence:”);
String str = in.nextLine();
word = “”;
}
else
{
word += ch;
}
}
System.out.println(“The longest word: “ + lWord +
“: The length of the word: “ + lWord.length());
}
}