Jerin Geogphy
Jerin Geogphy
Question 1(i)
Question 1(ii)
Identify the type of operator &&:1 ternary 2 unary3 logical 4 relational Answerlogical
Reason — Logical operators operate only on boolean operands and are used to construct complex decision-making
expressions. Logical AND && operator evaluates to true only if both of its operands are true.
Question 1(iii)
1. next()
2. nextLine()
3. Next()
4. nextString()
Answer
nextLine()
Reason — nextLine() reads the input till the end of line so it can read a full sentence including spaces.
Question 1(iv)
1. extends
2. export
3. import
4. package
Answer
import
Reason — import keyword is used to import built-in and user-defined packages into our Java program.
Question 1(v)
1. 16.0
2. 16
3. 4.0
4. 5.0
Answer
4.0
Reason — Math.ceil method returns the smallest double value that is greater than or equal to the argument and
Math.sqrt method returns the square root of its argument as a double value. Thus the given expression is evaluated
as follows:
Math.sqrt(Math.ceil (15.3))
= Math.sqrt(16.0)
= 4.0
Question 1(vi)
The absence of which statement leads to fall through situation in switch case statement?
1. continue
2. break
3. return
4. System.exit(0)
Answer
break
Reason — The absence of break statement leads to fall through situation in switch case statement.
Question 1(vii)
for (int i = 5; i != 0; i -= 2)
System.out.println(i);
1. finite
2. infinite
3. null
4. fixed
Answer
infinite
Reason — The given loop is an example of infinite loop as for each consecutive iteration of for loop, the value of i
will be updates as follows:
Iteration Value of i Remark
1 5 Initial value of i = 5
2 3 i=5-2=3
3 1 i=3-2=1
4 -1 i = 1 - 2 = -1
5 -3 i = -1 - 2 = -3 and so on...
Question 1(viii)
Write a method prototype name check() which takes an integer argument and returns a char:
1. char check()
2. void check (int x)
3. check (int x)
4. char check (int x)
Answer
Question 1(ix)
1. 1
2. 2
3. 3
4. 4
Answer
1. 20
2. 20 22
3. 2220
4. 22
Answer
20 22
Reason — The values of strings P and Q are converted into integers using the Integer.parseInt() method and
stored in int variables a and b, respectively.
When the statement System.out.println(a + " " + b) is executed, first the operation a + " " is performed.
Here, int variable a is converted to a string and a space is concatenated to it resulting in "20 ".
After this, the operation "20 " + b is performed resulting in 20 22 which is printed as the output.
Question 1(xi)
1. concat(String)
2. <string>.joint(string)
3. concat(char)
4. Concat()
Answer
concat(String)
Reason — concat() method is used to join two strings. Its syntax is as follows:
String1.concat(String2)
Question 1(xii)
1. POSI
2. POS
3. MPO
4. MPOS
Answer
POS
Reason — The substring() method returns a substring beginning from the startindex and extending to the character
at endIndex - 1. Since a string index begins at 0, the character at index 3 is 'P' and the character at index 5 (6-1 = 5)
is 'S'. Thus, "POS" is extracted.
Question 1(xiii)
1. implicit
2. automatic
3. explicit
4. coercion
Answer
explicit
Reason — In explicit type conversion, the data gets converted to a type as specified by the programmer. Here, the
float value 32.8 is being converted to int type by the programmer, explicitly.
Question 1(xiv)
1. source code
2. object code
3. machine code
4. java byte code
Answer
Reason — Java compiler converts Java source code into an intermediate binary code called Bytecode after
compilation.
Question 1(xv)
1. Logical
2. Syntax
3. Runtime
4. No error
Answer
Syntax
Reason — Syntax Errors occur when we violate the rules of writing the statements of the programming language.
Missing a semicolon in a statement is a syntax error.
Question 1(xvi)
Consider the following program segment and select the output of the same when n = 10 :
switch(n)
{
case 10 : System.out.println(n*2);
case 4 : System.out.println(n*4); break;
default : System.out.println(n);
}
1. 20
40
2. 10
4
3. 20, 40
4. 10
10
Answer
20
40
Reason — Since n = 10, case 10 will be executed. It prints 20 (10 * 2) on the screen. Since break statement is
missing, the execution falls through to the next case. Case 4 prints 40 (10 * 4) on the screen. Now the control finds
the break statement and the control comes out of the switch statement.
Question 1(xvii)
A method which does not modify the value of variables is termed as:
1. Impure method
2. Pure method
3. Primitive method
4. User defined method
Answer
Pure method
Reason — A method which does not modify the value of variables is termed as a pure method.
Question 1(xviii)
When an object of a Wrapper class is converted to its corresponding primitive data type, it is called as ............... .
1. Boxing
2. Explicit type conversion
3. Unboxing
4. Implicit type conversion
Answer
Unboxing
Reason — When an object of a Wrapper class is converted to its corresponding primitive data type, it is called as
unboxing.
Question 1(xix)
1. 1 bit
2. 2 bits
3. 4 bits
4. 16 bits
Answer
16 bits
1 byte = 8 bits
2 bytes = 8 * 2 = 16 bits
Question 1(xx)
Method which is a part of a class rather than an instance of the class is termed as:
1. Static method
2. Non static method
3. Wrapper class
4. String method
Answer
Static method
Reason — Method which is a part of a class rather than an instance of the class is termed as Static method.
Question 2(i)
Write the Java expression for (a + b)x.
Answer
Math.pow(a + b, x)
Question 2(ii)
x *= --x + x++ + x (x = 4)
x *= 3 + x++ + x (x = 3)
x *= 3 + 3 + x (x = 4)
x *= 3 + 3 + 4 (x = 4)
x *= 10 (x = 4)
x = x * 10 (x = 4)
x = 4 * 10
x = 40
Question 2(iii)
int x = 10;
do
{
x––;
System.out.print(x);
}while (x>=1);
Answer
Question 2(iv)
(b) Character.isLetterOrDigit('#')
Answer
Explanation
In Java, the Character.toUpperCase(char ch) method is used to convert a given character to its uppercase
equivalent, if one exists. So, the output is uppercase 'A'.
(b) Character.isLetterOrDigit('#')
Output
false
Explanation
Character.isLetterOrDigit() method returns true if the given character is a letter or digit, else returns false. Since,
hash (#) is neither letter nor digit, the method returns false.
Question 2(v)
int m = 400;
double ch = (m>300) ? (m / 10.0) * 2 : (m / 20.0) - 2;
Answer
int m = 400;
double ch = 0.0;
if(m > 300)
ch = (m / 10.0) * 2;
else
ch = (m / 20.0) - 2;
Question 2(vi)
Output
9
2
Explanation
d = n % 10; — This line calculates the remainder when n is divided by 10 and stores it in d. In the first
iteration, d will be 9 because the remainder of 4279 divided by 10 is 9.
System.out.println(d); — This line prints the value of d. In the first iteration, it will print 9.
n = n / 100; — This line performs integer division of n by 100. In the first iteration, n becomes 42.
(Remember, it is integer division so only quotient is taken and fractional part is discarded.)
Question 2(vii)
(a) "COMMENCEMENT".lastIndexOf('M')
(b) "devote".compareTo("DEVOTE")
Answer
(a) "COMMENCEMENT".lastIndexOf('M')
Output
Explanation
The lastIndexOf('M') method searches for the last occurrence of the character 'M' in the string
"COMMENCEMENT." In this string, the last 'M' appears at the index 8, counting from 0-based indexing. So, the
method returns the index 8 as the output, indicating the position of the last 'M' in the string.
(b) "devote".compareTo("DEVOTE")
Output
32
Explanation
compareTo() method compares two strings lexicographically. It results in the difference of the ASCII codes of the
corresponding characters. The ASCII code for 'd' is 100 and the ASCII code for 'D' is 68. The difference between
their codes is 32 (100 - 68).
Question 2(viii)
Consider the given array and answer the questions given below:
Answer
(a) 7
(b) 72
Question 2(ix)
(b) The method which has same name as that of the class name.
Answer
(a) Object.
(b) Constructor.
Question 2(x)
char ch ='d';
int n = ch + 5;
Answer
Explanation
1. char ch = 'd'; assigns the character 'd' to the variable ch. In ASCII, the character 'd' has a decimal value of
100.
2. int n = ch + 5; adds 5 to the ASCII value of 'd', which is 100. So, 100 + 5 equals 105.
Member variables:
name — name of student
age — age of student
mks — marks obtained
stream — stream allocated
Member methods:
void accept() — Accept name, age and marks using methods of Scanner class.
void allocation() — Allocate the stream as per following criteria:
mks stream
void print() – Display student name, age, mks and stream allocated.
import java.util.Scanner;
Output
Question 4
Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending order.
Display the sorted array and original array.
import java.util.Scanner;
System.out.println("Original Array");
for (int i = 0; i < ch.length; i++) {
System.out.print(ch[i] + " ");
}
//Bubble Sort
for (int i = 0; i < ch.length - 1; i++) {
for (int j = 0; j < ch.length - 1 - i; j++) {
if (ch[j] > (ch[j + 1])) {
char t = ch[j];
ch[j] = ch[j + 1];
ch[j + 1] = t;
}
}
}
System.out.println("\nSorted Array");
for (int i = 0; i < ch.length; i++) {
System.out.print(ch[i] + " ");
}
}
}
Output
Question 5
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
void print(int n) - To check whether the number is a lead number. A lead number is the one whose sum of even
digits are equal to sum of odd digits.
e.g. 3669
odd digits sum = 3 + 9 = 12
even digits sum = 6 + 6 = 12
3669 is a lead number.
import java.util.Scanner;
if(evenSum == oddSum)
System.out.println("Lead number");
else
System.out.println("Not a lead number");
}
System.out.println("Pattern: ");
obj.print();
Output
Question 6
Define a class to accept a String and print the number of digits, alphabets and special characters in the string.
Example:
S = "KAPILDEV@83"
Output:
Number of digits – 2
Number of Alphabets – 8
Number of Special characters – 1
import java.util.Scanner;
}
}
Output
Question 7
Define a class to accept values into an array of double data type of size 20. Accept a double value from user and
search in the array using linear search method. If value is found display message "Found" with its position where it
is present in the array. Otherwise display message "not found".
import java.util.Scanner;
if (i == l)
{
System.out.println("Not found");
}
else
{
System.out.println(n + " found at index " + i);
}
}
}
Output
Question 8
Define a class to accept values in integer array of size 10. Find sum of one digit number and sum of two digit
numbers entered. Display them separately.
Example:
Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1}
Output:
Sum of one digit numbers : 2 + 4 + 9 + 3 + 1 = 19
Sum of two digit numbers : 12 + 18 + 25 + 32 + 20 = 107
import java.util.Scanner;
}
}
Output