Computer PYQ 2015 2023
Computer PYQ 2015 2023
Give the output of the following statements: (b) What is the value of x1 if x=5? [2]
(i) System.out.println(x[1]);
x1= ++x – x++ + --x
(ii) System.out.println(x[3].length ( ));
(c) Why is an object called an instance of a class ? [2]
This Paper consists of 5 printed pages and 1 blank page.
T17 861 Turn Over
© Copyright Reserved T17 861 2
(d) Convert following do-while loop into for loop. [2] SECTION B (60 Marks)
int i = 1; Attempt any four questions from this Section.
int d=5; The answers in this Section should consist of the Programs in either Blue J environment or any
do { program environment with Java as the base.
d=d*2; Each program should be written using Variable descriptions/Mnemonic Codes so that the logic
System.out.println(d); of the program is clearly depicted.
i++ ; } while ( i<=5); Flow-Charts and Algorithms are not required.
(e) Differentiate between constructor and function. [2] Question 4.
(f) Write the output for the following: [2] Define a class ElectricBill with the following specifications: [15]
String s="Today is Test" ; class : ElectricBill
System.out.println(s.indexOf('T')); Instance variables / data member:
System.out.println(s.substring(0,7) + " " +"Holiday"); String n – to store the name of the customer
(g) What are the values stored in variables r1 and r2: [2] int units – to store the number of units consumed
(i) double r1 = Math.abs(Math.min(-2.83, -5.83)); double bill – to store the amount to be paid
(j) What is the difference between the Scanner class functions next() and [2] or not. (A number is spy if the sum of its digits equals the product of its digits.)
Question 7.
Write a program to input integer elements into an array of size 20 and perform the [15]
following operations:
(i) Display largest number from the array.
(ii) Display smallest number from the array.
(iii) Display sum of all the elements of the array.
Question 8.
Design a class to overload a function check( ) as follows: [15]
(i) void check (String str , char ch ) - to find and print the frequency of a character
in a string.
Example :
Input: Output:
str = "success" number of s present is =3
ch = 's'
(ii) void check(String s1) - to display only vowels from string s1, after converting
it to lower case.
Example :
Input:
s1 ="computer" Output : o u e
Question 9.
Write a program to input forty words in an array. Arrange these words in descending [15]
order of alphabets, using selection sort technique. Print the sorted array.
Answers to this Paper must be written on the paper provided separately. (ii) Name the package that contains wrapper classes.
You will not be allowed to write during the first 15 minutes. (b) State the difference between while and do while loop. [2]
This time is to be spent in reading the question paper. (c) System.out.print("BEST "); [2]
The time given at the head of this Paper is the time allowed for writing the answers. System.out.println("OF LUCK");
Choose the correct option for the output of the above statements
This Paper is divided into two Sections.
(i) BEST OF LUCK
Attempt all questions from Section A and any four questions from Section B.
(ii) BEST
The intended marks for questions or parts of questions are given in brackets[].
OF LUCK
(d) Write the prototype of a function check which takes an integer as an argument [2]
SECTION A (40 Marks) and returns a character.
Attempt all questions
(e) Write the return data type of the following function. [2]
(i) endsWith()
Question 1.
(ii) log()
(a) Define abstraction. [2]
(d) How are private members of a class different from public members? [2] √3𝑥 + 𝑥 2
𝑎+𝑏
(e) Classify the following as primitive or non-primitive datatypes: [2]
(b) What is the value of y after evaluating the expression given below? [2]
(i) char
y+= ++y + y-- + -- y; when int y=8
(ii) arrays
(c) Give the output of the following: [2]
(iii) int
(i) Math.floor (-4.7)
(iv) classes
(ii) Math.ceil(3.4) + Math.pow(2, 3)
This Paper consists of 6 printed pages. (d) Write two characteristics of a constructor. [2]
T18 861 Turn Over
© Copyright Reserved T18 861 2
(e) Write the output for the following: [2] SECTION B (60 Marks)
System.out.println("Incredible"+"\n"+"world"); Attempt any four questions from this Section.
(f) Convert the following if else if construct into switch case [2] The answers in this Section should consist of the Programs in either Blue J environment or any
if( var==1) program environment with Java as the base.
System.out.println("good"); Each program should be written using Variable descriptions/Mnemonic Codes so that the logic
else if(var==2) of the program is clearly depicted.
System.out.println("better"); Flow-Charts and Algorithms are not required.
else if(var==3) Question 4.
System.out.println("best"); Design a class RailwayTicket with following description: [15]
else
Instance variables/data members :
System.out.println("invalid");
String name : To store the name of the customer
(g) Give the output of the following string functions: [2]
String coach : To store the type of coach customer wants to
(i) "ACHIEVEMENT".replace('E', 'A')
travel
(ii) "DEDICATE".compareTo("DEVOTE")
long mobno : To store customer’s mobile number
(h) Consider the following String array and give the output [2]
int amt : To store basic amount of ticket
String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW",
int totalamt : To store the amount to be paid after updating
"JAIPUR"};
the original amount
System.out.println(arr[0].length()> arr[3].length());
Member methods :
System.out.print(arr[4].substring(0,3));
void accept () – To take input for name, coach, mobile number and amount.
(i) Rewrite the following using ternary operator: [2]
void update() – To update the amount as per the coach selected
if (bill >10000 )
discount = bill * 10.0/100; (extra amount to be added in the amount as follows)
else Type of Coaches Amount
discount = bill * 5.0/100; First_AC 700
Second_AC 500
(j) Give the output of the following program segment and also mention how many [2]
Third_AC 250
times the loop is executed: sleeper None
int i; void display() – To display all details of a customer such as name, coach, total
for ( i = 5 ; i > 10; i ++ ) amount and mobile number.
System.out.println( i );
Write a main method to create an object of the class and call the above member
System.out.println( i * 4 );
methods.
Write a program to input a number and check and print whether it is a Pronic number [15] Write a menu driven program to display the pattern as per user’s choice.
or not. (Pronic number is the number which is the product of two consecutive integers) Pattern 1 Pattern 2 [15]
Examples: 12 = 3 4 ABCDE B
ABCD LL
20 = 4 5 ABC UUU
AB EEEE
42 = 6 7 A
For an incorrect option, an appropriate error message should be displayed.
Question 6. Question 9.
Write a program to accept name and total marks of N number of students in two single [15]
Write a program in Java to accept a string in lower case and change the first letter of [15]
every word to upper case. Display the new string. subscript array name[ ] and totalmarks[ ].
Sample output: We Are In Cyber World (i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
(i) double volume (double R) – with radius (R) as an argument, returns the volume
of sphere using the formula.
V = 4/3 22/7 R3
(ii) double volume (double H, double R) – with height(H) and radius(R) as the
arguments, returns the volume of a cylinder using the formula.
V = 22/7 R2 H
(iii) double volume (double L, double B, double H) – with length(L), breadth(B) and
Height(H) as the arguments, returns the volume of a cuboid using the formula.
V=LBH
You will not be allowed to write during the first 15 minutes. int b = Integer.valueOf(Q);
System.out.println(a+""+b);
This time is to be spent in reading the question paper.
(c) What are the various types of errors in Java? [2]
The time given at the head of this Paper is the time allowed for writing the answers.
(d) State the data type and value of res after the following is executed: [2]
This Paper is divided into two Sections. char ch = '9';
Attempt all questions from Section A and any four questions from Section B. res= Character.isDigit(ch);
The intended marks for questions or parts of questions are given in brackets[ ]. (e) What is the difference between the linear search and the binary search [2]
technique?
SECTION A (40 Marks)
Attempt all questions Question 3.
(a) Write a Java expression for the following: [2]
2
| x +2xy |
Question 1.
(a) Name any two basic principles of Object-oriented Programming. [2] (b) Write the return data type of the following functions: [2]
(i) startsWith( )
(b) Write a difference between unary and binary operator. [2]
(ii) random( )
(c) Name the keyword which: [2]
(c) If the value of basic=1500, what will be the value of tax after the following [2]
(i) indicates that a method has no return type. statement is executed?
(ii) makes the variable as a class variable. tax = basic>1200 ? 200 :100;
(d) Write the memory capacity (storage size) of short and float data type in bytes. [2] (d) Give the output of following code and mention how many times the loop will [2]
execute?
(e) Identify and name the following tokens: [2]
int i;
(i) public
for( i=5 ; i>=1 ;i--)
(ii) 'a' {
if(i%2 ==1)
(iii) ==
continue;
(iv) { }
System.out.print( i+ '' '');
}
This Paper consists of 6 printed pages.
T19 861 Turn Over
© Copyright Reserved T19 861 2
(e) State a difference between call by value and call by reference. [2] double amount - To store the amount to be paid after discount
(i) String x[] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"}; [2] More than ` 10000 and less than or equal to ` 20000 10%
A 65
Question 4.
B 66
Design a class name ShowRoom with the following description: [15]
. .
Instance variables / Data members:
. .
String name - To store the name of the customer
long mobno - To store the mobile number of the customer . .
double cost - To store the cost of the items purchased Z 90
double dis - To store the discount amount
1 A tech number has even number of digits. If the number is split in two equal halves, [15]
1 2 then the square of sum of these halves is equal to the number itself. Write a program
to generate and print all four digits tech numbers.
1 2 3
1 2 3 4 Example:
= (55)2
Question 6.
Write a program to input 15 integer elements in an array and sort them in ascending [15] = 3025 is a tech number.
order using the bubble sort technique.
Question 7.
(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + ……………… xn terms
(c) void series ( ) – To display the sum of the series given below:
1 1 1 1
+ + ................
2 3 4 10
Question 8.
Write a program to input a sentence and convert it into uppercase and count and [15]
display the total number of words starting with a letter 'A'.
Example:
The time given at the head of this Paper is the time allowed for writing the answers. Question 3.
(a) Write a Java expression for the following: [2]
This Paper is divided into two Sections.
√𝑏 2 − 4𝑎𝑐
Attempt all questions from Section A and any four questions from Section B.
(b) Evaluate the following if the value of x=7, y=5 [2]
The intended marks for questions or parts of questions are given in brackets [ ].
x+=x++ + x + ++y
SECTION A (40 Marks) (c) Write the output for the following: [2]
Attempt all questions
String s1 = ''Life is Beautiful'';
(ii) The method which terminates the entire program from any stage. int k;
for ( k = 5 ; k < = 20 ; k + = 7 )
(d) Which of the following are primitive data types? [2]
if ( k% 6==0 )
(i) double
continue;
(ii) String
System.out.println ( k );
(iii) char
(f) What is the data type returned by the following library methods? [2]
(iv) Integer
(i) isWhitespace()
(e) What is an operator? Name any two types of operators used in Java. [2]
(ii) compareToIgnoreCase()
https://www.icseonline.com
(g) Rewrite the following program segment using logical operators: [2] SECTION B (60 Marks)
(h) Convert the following if else if construct into switch case: [2] of the program is clearly depicted.
Flow-Charts and Algorithms are not required.
if (ch== 'c' || ch=='C')
Question 4.
System.out . print(''COMPUTER'');
A private Cab service company provides service within the city at the following rates: [15]
else if (ch== 'h' || ch=='H')
AC CAR NON AC CAR
System.out . print(''HINDI''); UPTO 5 KM ₹ 150 /- ₹ 120 /-
BEYOND 5 KM ₹ 10/-PER KM ₹ 08/- PER KM
else
Design a class CabService with the following description:
System.out . print(''PHYSICAL EDUCATION''); Member variables /data members:
(i) Give the output of the following: [2] String car_type - To store the type of car (AC or NON AC)
(i) Math.pow (36,0.5) + Math.cbrt (125) double km - To store the kilometer travelled
(ii) Math.ceil (4.2 ) + Math.floor (7.9) double bill - To calculate and store the bill amount
Member methods :
(j) Rewrite the following using ternary operator: [2]
CabService() - Default constructor to initialize data members.
if(n1>n2)
String data members to '' '' and double data
r = true;
members to 0.0.
else
void accept () - To accept car_type and km (using Scanner class
r = false; only).
void calculate () - To calculate the bill as per the rules given above.
CAR TYPE:
KILOMETER TRAVELLED:
TOTAL BILL:
Create an object of the class in the main method and invoke the member methods.
Write a program to search for an integer value input by the user in the sorted list given [15] Write a menu driven program to perform the following operations as per user’s choice: [15]
below using binary search technique. If found display ''Search Successful'' and print (i) To print the value of c=a2+2ab, where a varies from 1.0 to 20.0 with increment
the element, otherwise display ''Search Unsuccessful'' of 2.0 and b=3.0 is a constant.
{31, 36, 45, 50, 60, 75, 86, 90} (ii) To display the following pattern using for loop:
A
Question 6. AB
ABC
Write a program to input a sentence and convert it into uppercase and display each [15]
ABCD
word in a separate line. ABCDE
Example: Input : India is my country Display proper message for an invalid choice.
Output : INDIA
Question 9.
IS
Write a program to input and store integer elements in a double dimensional array of [15]
MY
size 3 x 3 and find the sum of elements in the left diagonal.
COUNTRY
Example:
Question 7. 1 3 5
num = 2565685
d=5
Frequency of digit 5 = 3
(ii) void Number (int n1) - To find and display the sum of even digits of
a number.
Example:
n1 = 29865
Write a main method to create an object and invoke the above methods.