Class 10 Java Paper 2019
Class 10 Java Paper 2019
Section A
Question 1
Answer
1. Encapsulation
2. Inheritance
Answer
unary operators operate on a single operand whereas binary operators operate on two
operands.
Answer
1. void
2. static
(d) Write the memory capacity (storage size) of short and float data type in bytes.
Answer
1. short — 2 bytes
2. float — 4 bytes
1. public
2. 'a'
3. ==
4. {}
Answer
1. Keyword
2. Literal
3. Operator
4. Separator
Question 2
Answer
if else if switch-case
if else if can test for any Boolean expression like less than, switch-case can only test if the expression is
greater than, equal to, not equal to, etc. equal to any of its case constants.
if else if can use different expression involving unrelated switch-case statement tests the same
variables in its different condition expressions. expression against a set of constant values.
2019
Explanation
Answer
1. Syntax Error
2. Runtime Error
3. Logical Error
(d) State the data type and value of res after the following is executed:
char ch = '9';
res= Character.isDigit(ch);
Answer
Data type of res is boolean as return type of method Character.isDigit() is boolean. Its value is
true as '9' is a digit.
(e) What is the difference between the linear search and the binary search technique?
Answer
In Linear search, each element of the array is In Binary search, array is successively divided into 2
checked against the target value until the element halves and the target element is searched either in the
is found or end of the array is reached. first half or in the second half.
Question 3
Answer
Math.abs(x * x + 2 * x * y)
1. startsWith()
2. random()
Answer
1. boolean
2. double
(c) If the value of basic=1500, what will be the value of tax after the following statement
is executed?
Value of tax will be 200. As basic is 1500, the condition of ternary operator — basic > 1200 is
true. 200 is returned as the result of ternary operator and it gets assigned to tax.
(d) Give the output of following code and mention how many times the loop will
execute?
int i;
for( i=5; i>=1; i--)
{
if(i%2 == 1)
continue;
System.out.print(i+" ");
}
Answer
4 2
Loop executes 5 times. The below table shows the dry run of the loop:
i Output Remark
0 42 As condition of loop (i >= 1) becomes false so loops exits and 6th iteration does not happen.
Answer
In call by value, actual parameters are copied to formal parameters. Any changes to formal
parameters are not reflected onto the actual parameters. In call by reference, formal
parameters refer to actual parameters. The changes to formal parameters are reflected onto
the actual parameters.
Answer
phoenixland
ISLAND
Explanation
s1.substring(0) results in phoenix. s2.substring(2) results in land. concat method joins both of
them resulting in phoenixland. s2.toUpperCase() converts island to uppercase.
(h) Evaluate the following expression if the value of x=2, y=3 and z=1.
Answer
v = x + --z + y++ + y
⇒v=2+0+3+4
⇒v=9
(i) String x[] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"};
1. System.out.println(x[3]);
2. System.out.println(x.length);
Answer
1. Big data
2. 4
Answer
A package is a named collection of Java classes that are grouped on the basis of their
functionality. For example, java.util.
Section B
Question 4
Design a class name ShowRoom with the following description:
Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based on following
criteria
void display() — To display customer name, mobile number, amount to be paid after discount.
Write a main method to create an object of the class and call the above member methods.
Answer
import java.util.Scanner;
public ShowRoom()
{
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}
public void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = in.nextLine();
System.out.print("Enter customer mobile no: ");
mobno = in.nextLong();
System.out.print("Enter cost: ");
cost = in.nextDouble();
}
Output
Question 5
Using the switch-case statement, write a menu driven program to do the following:
Letters Unicode
A 65
B 66
. .
. .
. .
Z 90
1
12
123
1234
12345
Answer
import java.util.Scanner;
case 2:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++)
System.out.print(j + " ");
System.out.println();
}
break;
default:
System.out.println("Wrong choice");
break;
}
}
}
Output
Question 6
Write a program to input 15 integer elements in an array and sort them in ascending order
using the bubble sort technique.
Answer
import java.util.Scanner;
//Bubble Sort
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
System.out.println("Sorted Array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}
Output
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:
Answer
void series(int p) {
for (int i = 1; i <= p; i++) {
int term = (int)(Math.pow(i, 3) - 1);
System.out.print(term + " ");
}
System.out.println();
}
void series() {
double sum = 0.0;
for (int i = 2; i <= 10; i++) {
sum += 1.0 / i;
}
System.out.println("Sum = " + sum);
}
}
Output
Question 8
Write a program to input a sentence and convert it into uppercase and count and display the
total number of words starting with a letter 'A'.
Example:
Answer
import java.util.Scanner;
Output
Question 9
A tech number has even number of digits. If the number is split in two equal halves, 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.
Example:
Answer
Output