861-22-5
861-22-5
SAMPLE PAPER - 5
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.)
{
for (int i = a.length / 2; i < a.length; i++)
{
a[i] = a[i] * 2;
}
}
(a) {-20, -10, 2, 8, 16, 60} (c) {-10, -5, 1, 8, 16, 60}
(b) {-20, -10, 2, 4, 8, 30} (d) {-10, -5, 1, 4, 8, 30}
(viii) Given a string str= “SoftwareandHardware” The return type of str.length() + str.indexOf(‘w’) will be :
(a) float (b) double (c) int (d) String
(ix) The output of the following code is :
public class numbers
{
public static void main(String[] args)
{
int arr[ ]={5,10,15,20,25};
int s=0;
for(int i=0;i<arr.length;i++)
{
arr[i]=arr[i]-1;
s=s+arr[i];
}
System.out.println(s);
}
}
(a) 70 (b) 69 (c) 50 (d) 80
(x) Given a string str=”Barrackpore”;
The statement str.substring(5).toUpperCase() returns :
(a) ckpore (b) Barrac (c) CKPORE (d) ackpor
Question 6.
Define a class to input numbers into an array and remove the odd elements.
import java.util.Scanner;
Question 7.
A string is said to be ‘Unique’ if none of the letters present in the string are repeated. Write a program
to accept a string and check whether the string is Unique or not. The program displays a message
accordingly.
Sample Input: COMPUTER
Sample Output: Unique String
Answers
Section-A
Answer 1.
(i) (a) 740
Explanation :
Integer.parseInt(“670”) returns 670 and Integer.parseInt (“70”) returns 70, 670+70 = 740
(ii) (b) False
Explanation :
Character.isLetter(‘a’) returns “True” , Character.isUpperCase(‘t’) returns “False”, True && False gives
False
(iii) (d) Binary search
Explanation :
In a binary search the middle index is found and the array is divided into 2 halves to search for an
element.
(iv) (b) 7
Explanation :
str.substring(5,12) returns characters from index 5 to 11 which are 7 characters.
(v) (d) No output
Explanation :
str.substring(2,2) returns nothing as start and end index are same.
(vi) (c) 455610
Explanation :
The statement String c = a+b +”10” creates c as concatenation of “45”,”55” and “10 = 455510. The
statement System.out.println(m+n+Integer.parseInt(c)+””); calculates 45 +55 + 455510= 455610
(vii) (c) {-10, -5, 1, 8, 16, 60}
Explanation :
It loops from the middle to the end doubling each value. Since there are 6 elements it will start at
index 3.
(viii) (c) int
Explanation :
str.length() returns the length of the string which is an integer and str.indexOf(‘w’) returns the first
index of ‘w’ in the string. Sum of the two is an integer.
(ix) (a) 70
Explanation :
The loop subtracts 1 from each element of the array and sums each of them , which is printed.
(x) (c) CKPORE
Explanation :
str.substring(5) returns “ckpore” and toUpperCase() converts it to CKPORE
Section-B
Answer 2.
import java.util.Scanner;
public class TruncateArray
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
double a[] = new double[10];
int b[] = new int[10];
System.out.println(“Truncated numbers”);
for (int i = 0; i < b.length; i++)
{
System.out.print(b[i] + “, “);
}
}
}
Answer 3.
import java.util.Scanner;
public class MaxVowelWord
{
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 = “”, mWord = “”;
int count = 0, maxCount = 0;
int len = str.length();
char ch = Character.toUpperCase(str.charAt(i));
if (ch == ‘A’ ||
ch == ‘E’ ||
ch == ‘I’ ||
ch == ‘O’ ||
ch == ‘U’)
{
count++;
}
if (ch == ‘ ‘)
{
if (count > maxCount)
{
maxCount = count;
mWord = word;
}
word = “”;
count = 0;
}
else
{
word += ch;
}
}
System.out.println(“The word with maximum number of vowels: “ + mWord);
}
}
Answer 4.
public class StringReplace
{
public static void main(String args[])
{
String str = “Blue bottle is in Blue bag lying on Blue carpet”;
str += “ “;
String newStr = “”;
String word = “”;
String target = “Blue”;
String newWord = “Red”;
int len = str.length();
}
System.out.println(newStr);
}
}
Answer 5.
import java.util.Scanner;
public class CopyArray
{
public static void main(String[] args)
{
System.out.println(“Array1”);
for (int i-0;i<src1.length;i++)
System.out.print(src1[i]);
System.out.print(“Array2”);
for (int i-0;i<src2.length;i++)
System.out.print(src2[i]);
System.out.print(“Merged Array”);
for (int i-0;i< newArray.length;i++)
System.out.print(newArray[i]);
}
}
Answer 6.
public class Array
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print(“Enter size of the array: “);
int n = scan.nextInt();
int numbers[] = new int[n];
System.out.println(“Enter array elements: “);
for (int i = 0; i < n; ++i)
{
numbers[i] = scan.nextInt();
}
int newArr[] = removeOdd(numbers);
System.out.println(“Array after removing odd numbers: “ + Arrays.toString(newArr));
scan.close();
}
public static int[] removeOdd(int[] numbers)
{
int countEven = 0;
int even[] = null;
int i = 0;
for (int num : numbers)
{
if (num % 2 == 0)
{
// even
even[i++] = num;
}
}
return even;
}
}
Answer 7.
import java.util.Scanner;
public class UniqueString
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print(“Enter a string: “);
String str = in.nextLine();
str = str.toUpperCase();
boolean isUnique = true;
int len = str.length();
char ch = str.charAt(i);
for (int j = i + 1; j < len; j++)
{
if (ch == str.charAt(j))
{
isUnique = false;
break;
}
}
if (!isUnique)
break;
}
if (isUnique)
System.out.println(“Unique String”);
else
System.out.println(“Not Unique String”);
}
}