[go: up one dir, main page]

0% found this document useful (0 votes)
23 views4 pages

Icse 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Icse 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMPUTER APPLICATIONS

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

19. What is the output of the following code?


String str = "Java Programming";
System.out.println(str.replace('a', 'x'));
a) Jxvx Programming b) Jxvx Progrxmming c) Jxxv Progrxmming d) Jv Progrmming
20. What will be the output of the following code?
public class Test {
public static void main(String[] args) {
int a = 10;
int b = 20;
Test.swap(a, b);
System.out.println("a: " + a + ", b: " + b);
}
public static void swap(int x, int y) {
int temp = x;
x = y;
y = temp;
}
}
a) a: 10, b: 20 b) a: 20, b: 10 c) a: 10, b: 10 d) a: 20, b: 20
Question 2
i. What do you mean by the scope of a variable? What is the scope of a variable declared within a
function?
ii. What is a function signature in Java? Why is it important?
iii. What is the purpose of the `break` statement in a `switch` case? What would happen if it were
omitted?
iv. Write a Java function that takes a string and returns the number of vowels (a, e, i, o, u) in the string.

v. Give the output of the following String class methods:


i. "COMMENCEMENT" . lastIndexOf('M')
ii. "devote" . compareTo("DEVOTE")
vi. Given the string str = "Java Programming", write a Java code snippet to find the First occurrence of
the substring "gram" and print its index.
vii. Describe the purpose of the return statement in a Java function. Provide an example demonstrating a
function that returns a value and a function that does not.
viii. Explain the concept of immutability in strings. Why are strings immutable in Java?
ix. What are the differences between == and equals() when comparing strings in Java? Give an example
to illustrate your answer
x. Describe the process of concatenating strings in Java.

SECTION B (60 marks)

Answer any four of the following questions. Each question carries 15 marks

Question 1: [15 marks]


Write a Java program that performs the following tasks related to string handling and functions:
1. Read a paragraph of text from the user.
2. Implement a function public static int wordCount(String str) that counts and returns the number of
words in the given paragraph.
3. In the main method, call the relevant functions
Question 2:
[15marks]
Implement a Java function public static boolean isPalindrome(String str) that checks whether a given string is
a palindrome. The function should ignore spaces, punctuation, and case differences. Write a main method to
test your function with different inputs.

Question 3: [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.

Question 4: [15 marks]

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.

Question 5: [15 marks]


Write overloaded functions named `area` to calculate the area of a square and rectangle.
void area(int s) : The function for the square should take one parameter (side length),
void area (int l, int b) : The function for the rectangle should take two parameters (length and breadth).
Use them in main method to calculate area of square or rectangle and determined by the user.

Question 6: [15 marks]

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.

You might also like