Icse 10
Icse 10
ICSE – X
This paper is divided into two sections
Attempt all questions from Section A and any four from Section B
The intended marks for each question are given in brackets[]
SECTION A (40 marks)
Attempt all questions
Question 1 [20]
Choose the correct answers to the questions from the given options:
1. Which of the following is used to exit a function and return a value to the calling function?
a) exit b) break c) return d) send
2. Which of the following methods is used to convert all characters in a string to uppercase in Java?
a) toUpperCase() b) toLowerCase() c) charAt() d) substring()
3. Which method is used to compare two strings for equality in Java?
a) compareTo() b) equals() c) compare() d) ==
4. The output of the function "COMPOSITION".substring(3, 6):
(a) POSI (b) POS (c) MPO (d) MPOS
5. Which of the following is used to compare two strings lexicographically in Java?
a) compareTo() (b) equals() (c) compare() (d) compareWith()
6. Which of the following if-else statements is syntactically correct?
a) if(x > 10) System.out.println("x is greater than 10");
else; System.out.println("x is not greater than 10");
b) if(x > 10) { System.out.println("x is greater than 10"); }
else { System.out.println("x is not greater than 10"); }
c) if x > 10 { System.out.println("x is greater than 10"); }
else { System.out.println("x is not greater than 10"); }
d) if(x > 10) { System.out.println("x is greater than 10")
else { System.out.println("x is not greater than 10"); }
7. What is the purpose of the continue statement in a loop?
a) To exit the loop
b) To skip the current iteration and proceed to the next iteration
c) To exit the current function
d) To repeat the current iteration
8. What is the output of the following code?
String s = "Hello, World!";
System.out.println(s.substring(7));
a) Hello b) World c) World! d) Hello, W
9. Which method is used to find the length of a string in Java?
a) size() b) length() c) getSize() d) getLength()
10. How do you check if a string starts with a specific prefix in Java?
a) startsWith() b) beginsWith() c) hasPrefix() d) starts()
11. Which of the following methods can be used to convert a string to an integer in Java?
a) Integer.valueOf(str) b) Integer.parseInt(str) c) String.toInt(str) d) Both a and b
12. What will be the output of the following code?
String str1 = "Hello";
String str2 = "World";
System.out.println(str1.concat(" ").concat(str2));
a) Helloworld b) Hello World c) HelloWorld d) "Hello World"
13. How do you define a function in Java that returns a string and takes an integer as a parameter?
a) String functionName(int param)
b) String functionName(int param) { }
c) void functionName(int param) { return ""; }
d) string functionName(int param) { }
14. What will the following code print?
public static void main(String[] args)
System.out.println("Length: " + getStringLength("Hello World"));
}
public static int getStringLength(String str) {
return str.length();
}
a) Length: 10 b) Length: 11 c) Length: 12 d) Length: 0
15. How do you replace all occurrences of 'a' with 'e' in a string str?
a) str.replaceAll('a', 'e') b) str.replace('a', 'e')
c) str.replace('a').with('e') d) str.replaceChars('a', 'e')
16. In Java, which keyword is used to declare a function that does not return any value?
a) void b) null c) empty d) none
17. Which method can be used to check if a string contains a certain sequence of characters?
a) contains() b) includes() c) hasSubstring() d) indexOf()
18. What will be the result of the following code?
public class Test {
public static void main(String[] args) {
System.out.println(factorial(5));
}
public static int factorial(int n) {
if (n < 0)
System.out.println("n must be non-negative");
int result = 1;
for (int i = 1; i <= n; i++)
result *= i;
return result;
}
}
a) 120 b) 24 c) 5 d) 0
Answer any four of the following questions. Each question carries 15 marks
Write a program which has a function `String dayOfWeek(int day) ` that takes an integer (1 for Monday, 2 for
Tuesday, ..., 7 for Sunday) and returns the corresponding day using a `switch` statement.
Write the main function which inputs a value and passes it to `dayOfWeek` function.
Write a Java function public static String removeDuplicates(String str) that takes a string and returns a new
string with all duplicate characters removed. For example, the input "programming" should return "progamin".
Write a main method to test your function with different values.
Write a java program to create a temperature unit converter using functions. It should have the following
functions:
1. A function named celsiusToFahrenheit which takes a Celsius value and returns the temperature value
converted to Fahrenheit. It should use the formula:
Fahrenheit = (Celsius * 9/5) + 32
2. A function named fahrenheitToCelsius which takes a Fahrenheit value and returns the temperature
value converted to Celsius. It should use the formula:
(Fahrenheit - 32) * 5/9
Write a main method to ask the user whether he/she will enter Celsius or Fahrenheit value and call the relevant
function to convert Celsius to Fahrenheit or vice versa.