JNS Ca Prelim 1 Paper

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

FIRST PRELIMINARY EXAMINATION – November/December - 2022

COMPUTER APPLICATIONS ( GROUP III ELECTIVE)


Std. : 10
Time: 2 hrs.
Marks: 100
Date: 14/12/2022
___________________________________________________________________________
Answer to this Paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 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.
The intended marks for questions or parts of questions are given in brackets [ ].
This paper consists of 9 printed pages.

SECTION A
(Attempt all questions from this Section.)
Question-1 Choose the correct answer and write the correct option. [20]

(i) A __________________ is an exit-controlled loop in Java.


a. while
b. do…while
c. for
d. switch
(ii) Name the type of error in the statement given below:
int r= 100/0;
a. Syntax error
b. Run time error
c. Logical error
d. None of the above
(iii) How many elements are there in an array marks?
int marks[ ] = {23,56,78,87,45};
a. 6
b. 4
c. 5
d. 7

1
(iv) Which of these operators is used to allocate memory to array variable in Java?
a. alloc
b. malloc
c. new
d. new malloc

(v) Modulus operator (%) can be applied to which of these?


a. Integers
b. Floating point numbers
c. Strings
d. Both a and b

(vi) int result = ‘C’; What is the value of result?


a. C
b. 67
c. 66
d. 99

(vii) Which of the following are not Java keywords?


a. double
b. char
c. then
d. case

(viii) Which of the given operators can be used to concatenate two or more String objects?
a. +
b. +=
c. &
d. ||

(ix) What will be the value stored in the variable ‘c’ after the following statement is
executed?
char c = “DECODING”.charAt(2);
a. C
b. E
c. D
d. C

(x) In java, array elements are stored in ________ memory locations.


a. sequential
b. sequential and random
c. random
d. dynamic
(xi) The class string belongs to ________________ package.

2
a. java.lang
b. java.awt
c. java.string
d. java.applet

(xii) Consider the following code and predict the output.


public class Test
{
public static void main(String[] args) {
String s = new String("5");
System.out.println(1 + 10 + s + 1 + 1);

}
}

a. 1152
b. 11511
c. 1105110
d. 18

(xiii) The output of the method “HELLO”.substring(0,2) is :


a. “HE”
b. “EL”
c. “he”
d. “el”

(xiv) Automatic conversion of primitive data into an object of wrapper class is called
_______________.
a. autoboxing
b. explicit conversion
c. shifting
d. wrapping

(xv) Which of the following functions is used to remove leading and trailing white spaces
from the string?
a. trail()
b. truncate()
c. slice()
d. trim()

(xvi) Parameters used in method call statement are known as ____________________.


a. formal parameters
b. actual parameters
c. defined parameters
d. passed parameters

3
(xvii) Which of the following is not a part of looping construct?
a. for
b. break
c. continue
d. close

(xviii) Which of the following statements will terminate the premature execution of a
program?
a. break
b. System.exit(0)
c. stop
d. end

(xix) What value will be stored in the variable p after executing the following code?
double a = -6.35;
double p = Math.abs(Math.ceil(a));
a. 6.5
b. 6.0
c. 6.35
d. -6.0

(xx) We can calculate the length of an array using ________.


a. sizeof(array)
b. array.len
c. array.length
d. array.sizeof()

Question-2
i. What will be the output of the following code? [2]

class try
{
public static void main(String args[])
{
int y = 10;
int z=(++y * (y++ - 5));
System.out.println(y + ", " + z );
}
}

4
ii. What will be the output of the following code? [2]
class Main
{
public static void main(String args[])
{
int array_variable [] = new int[10];
for (int i = 0; i < 10; ++i)
{
array_variable[i] = i;
System.out.print(array_variable[i] + " ");
i++;
}
}
}

iii. How many times will the following loop execute? What value will be value stored in y [2]
?
int x = 2, y = 50;
do
{
++x;
y- = x++;
} while(x <= 10);

iv. Rewrite the following program segment using if-else construct. [2]
String grade=(mark>=90) ? “A” : (mark>=80) ? “B” : “C”.

v. Write the output of the following code segment: [2]


char ch; int x = 97;
do
{
ch = (char)x;
System.out.print(ch+“ ”);
if(x%10==0)
break;
++x;
} while(x<=100);

5
vi. Write function prototypes for the following: [2]
a. A method InChar which takes a string argument st and a character argument
ch and returns an integer value.
b. A method check which receives a character argument ch and an integer
argument n and returns true or false.

vii. What is the difference between isUpperCase() and toUpperCase() method? [2]

viii. Give the output of the following code: [2]


String n = “Computer Applications”;
String m = “Computer Science”;
System.out.println(n.substring(0,8).concat(m.substring(9)));

ix. class First [2]


{
public static void main(String args[])
{
int a[]={5,1,15,20,25};
int i,j;
int m;
i=++a[1];
j=a[2]++;
m=a[i++];
System.out.print(i+" "+j+" "+m);
}
}

x. Predict the output of the following: [2]


a. String str = “String Manipulation”;
int p = str.indexOf(‘n’);
System.out.println(p);
b. String smp = “Technology Is Fun”;
System.out.println(smp.length());

6
SECTION B

(Answer any four questions from this Section.)


The answer in this section should consist of programs in either BlueJ environment or any program
environment with java as the base.
Each program should be written using variable description / mnemonic codes so that the logic of the
program is clearly depicted.
Flowcharts and algorithms are not required.

Question-3 Define a class with the following specifications. [15]


Class name : Salary
Data Members/Instance Variables
Name : to store name of the teacher
Address : to store teacher’s address
Phone : to store teacher’s mobile number
Subject : to store subject specialization
MonthlySal : to store monthly salary
Income Tax : to store income tax
Functions/Member methods
Salary(String nam, String add, int pno,String sub, int mon_sal): parameterised
constructor to assign nam to Name, add toaddress, pno to
Phone, sub to Subject, mon_sal to MonthlySal
compute() : compute the annual income tax as 5% of the annual salary above `
₹ 1,75,000
display() : displays the details of the teacher in the format given
Name : _____________________
Address : ______________________
Phone : _____________________
Subject : ______________________
Monthly Salary : __________________
Income Tax : _________________

Write a main() method and create 2 objects to calculate tax for 2 teachers and call the
above methods accordingly.

7
Question-4 Write a program to accept the year of graduation from the user as an integer value. [15]
Using the binary search technique on the sorted array Gy[] given below, output the
message “Record Exists ” with its position - if the value is located in the array. If not,
output the message “Record does not exist”.

Gy[0] Gy[1] Gy[2] Gy[3] Gy[4] Gy[5] Gy[6] Gy[7] Gy[8] Gy[9]
1990 1992 1994 1998 1999 2002 2004 2008 2010 2014

Sample Input : Enter the graduation year ( 1998)


Sample Output : Record Exists at 4th position in the array

Sample Input : Enter the graduation year ( 2005)


Sample Output : Record does not exists…..

Question-5 Write a program in Java to input a number and check whether it is a Unique number [15]
or not. [A number is said to be unique , if the digits in it are not repeated. for example,
12345 is a unique number. 123445 is not a unique number.].

Sample Input. : Enter the number: 4356


Sample Output : 4356 is a unique number

Sample Input. : Enter the number: 45564


Sample Output : 45564 is not a unique number

Question-6 Design a class to overload a function check ( ) as follows : [15]


(i) int check (String str, char ch) – to find and return the frequency of a character in a
string.
Sample Input: Enter the string : str = “success”
Enter the character = ‘s’ .
Sample Output: number of s present is = 3

(ii) void check(String s1) – to display only vowels from string s1 after converting it to
to lower case.
Sample Input : Enter String : s1 = “computer”
Sample Output: The vowels in the string are : o u e

(iii) char check(String st, int idx) - to display the character at the specified index (idx)
in a string
Sample Input : Enter String : st = “Technology”
Enter the index : 3
Sample Output: The character at index 3 is : h

8
Question-7 Special words are those words which start and end with the same letter. [15]
Examples: EXISTENCE COMIC WINDOW .
Palindrome words are those words which read the same from left to right and vice
versa.
Examples: MALAYALAM MADAM LEVEL ROTATOR CIVIC

All palindromes are special words, but all special words are not palindromes. Write a
program to accept six words in an array arrWord[] . Check and print the palindrome
and special words and only special word from the array an array and also print their
frequency.

Sample Input :
COMIC ICICI MOM MALYALAM EXISTENCE DAD

Sample Output :
Palindrome and Special Words are : ICICI, MOM, MALYALAM,DAD
Frequency of Palindrome and Special words : 4
Special Words are : COMIC, EXISTENCE
Frequency of Special Words : 2

Question-8 Write a program to input 10 numbers into an integer type array and arrange the [15]
numbers in descending order using Bubble Sort technique.

Sample Input : Enter any 10 numbers in an array


67, 12, 45, 34, 32, 99, 87, 69, 88, 3

Sample Output : Array after sorting is :


99, 88, 87, 69, 67, 45, 34, 32, 12, 3

_____________________________________________________________________

You might also like