861 Set1
861 Set1
SAMPLE PAPER - 2
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.)
Section-A
Answer 1.
(i) (c) Wrapper class
Explanation :
Each primitive data type has a canvas of wrapper class . The wrapper classes have associated functions
to deal with the associated data types.
(ii) (a) Encapsulation
Explanation :
The OOPs feature Encapsulation encapsulates data and functions of a class as one unit and shields
them from the outside world.
(iii) (d) 44
Explanation :
x[1+2] means x[3] , here x[3] is 44
(iv) (b) Boolean
Explanation :
Boolean is the wrapper class for the Boolean primitive data type.
(v) (c) startsWith()
Explanation :
The startsWith() function checks whether a string begins with a particular string or not and returns a
boolean true or false.
(vi) (a) System.out.println(str.substring(2,4).toUpperCase());
Explanation :
The substring(2,4) extracts characters from index 2 to 3 and toUpperCase() converts them to uppercase
(vii) (c) Protected
Explanation :
The protected access specifier can be used to make accessibility to own class, classes of same package
and child classes.
(viii) (c) trn.substring(7).toUpperCase()
Explanation :
The trn.substring(7) returns the characters from index 7 to the end of the string i.e : ‘Express’ and the
toUpperCase() function converts it to uppercase to return ‘EXPRESS’.
(ix) (b) Laxman
Explanation :
s1=s2 assigns s2 to s1 , which is then printed.
Section-B
Answer 2.
Example :
Input : Enter 6 numbers: 10 20 30 40 50 60
Output : After swap list are: 20 10 40 30 60 50
import java.util.Scanner;
class SwapNums
{
public static void main(String args[])
{
int i, t;
int arr[] = new int[6];
Scanner sc = new Scanner(System.in);
System.out.print(“Enter 6 numbers:”);
for (i = 0; i < 6; i++)
{
arr[i] = sc.nextInt();
}
i = 0;
while (i < 6 - 1)
{
t = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = t;
i = i + 2;
}
System.out.print(“After swap list are:”);
for (i = 0; i < 6; i++)
{
System.out.print(“ ” + arr[i]);
}
}
}
Answer 3.
class Student
{
int roll;
String name ;
float term1marks;
float term2marks;
float perc;
public void getStudent()
{
Scanner sc=new Scanner(System.in);
roll=sc.nextInt();
name=sc.nextLine();
term1marks=sc. nextFloat();
term2marks= sc. nextFloat();
perc=(term1marks + term2marks)/2;
}
public void showStudent( )
{
System.out.println(“Name :”+ name)
System.out.println(“Percentage:”+perc);
}
}
Answer 4.
import java.util.Scanner;
public class PalinWords
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter a sentence:”);
String str = in.nextLine();
str = str + “ ”;
String word = “ ”;
int len = str.length();
word = “”;
}
else
{
word += ch;
}
}
}
}
Answer 5.
import java.util.*;
class search
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String [] str= new String[10];
int flag=0,i;
System.out.println(“Enter 10 strings :”);
for(i=0;i<10;i++)
str[i] = sc.nextLine();
System.out.println(“Enter the name to search :-”);
String s=sc.nextLine();
for(i=0;i<10;i++)
{
if(s==stri])
{
flag=1;
break;
}
}
if(flag==1)
System.out.println(“The name “+s+” Exists”);
else
System.out.println(“The name “+s+” does not Exist”);
}
}
Answer 6.
import java.util.Scanner;
public class check_words
{
public static void main(String[] args)
{
String sentence;
String word;
String w = “”;
int len, i, f = 0;
Scanner obj= new Scanner(System.in);
System.out.println(“Enter the sentence: “); // enter the sentence
sentence = obj.nextLine();
sentence = sentence + “ “; // add space at the end of sentence
len = sentence.length();
{
ch = str.charAt(i);
if (ch != ‘ ‘)
{
word += ch;
}
//if ends
else
{
l = word.length();
if (l < min)
{
min = l;
sword = word;
}
//if ends
if (l > max)
{
max = l;
lword = word;
}
word = “”;
}
}
System.out.println(“Shortest word = ” + sword + “ with length ” + min);
System.out.println(“Longest word = ” + lword + “ with length ” + max);
}
}