0% found this document useful (0 votes)
12 views

Coding Set 2 Questions

Uploaded by

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

Coding Set 2 Questions

Uploaded by

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

CODING SET 2

1. What is the result of the expression `"Hello" + b) Using triple double-quotes: """..."""
"World"` in Python?
c) Using backslashes at the end of each line: \
a) "HelloWorld"
d) Using parentheses: (...)
b) "Hello World"
7. What method can be used to convert a string
c) "Hello" + " " + "World" to all uppercase letters in Python?

d) Error a) `to_upper()`

2. In Python, strings are: b) `upper()`

a) Mutable c) `uppercase()`

b) Immutable d) `capitalize()`

3. Which method is used to find the length of a 8. Which of the following statements is true
string in Python? regarding string indexing in Python?

a) `length()` a) Python uses zero-based indexing.

b) `len()` b) Python uses one-based indexing.

c) `count()` c) Python uses negative indexing.

d) `size()` d) Strings cannot be indexed in Python.

4. How can you check if a string `my_string` 9. What is the output of `len("Python")`?
starts with the substring `"Hello"`?
a) 5
a) `my_string.starts_with("Hello")`
b) 6
b) `my_string.startswith("Hello")`
c) 7
c) `my_string.begins_with("Hello")`
d) 8
d) `my_string.starts("Hello")`
10. Which escape sequence is used to represent a
5. What will `str(123)` return? newline character in a string?

a) "123" a) \n

b) 123 b) \t

c) "0b1111011" c) \\

d) Error d) \r

6. Which of the following is not a valid way to


create a multi-line string in Python?
11. What will the expression `"Hello" * 3`
a) Using triple single-quotes: '''...''' evaluate to?
a) "HelloHelloHello" 16. Which of the following is a valid string in
Python?
b) "Hello 3 times"
a) 'Hello, World!"
c) ["Hello", "Hello", "Hello"]
b) "Hello, World!"
d) Error
c) 'Hello, World!'
12. How can you remove leading and trailing
whitespace from a string in Python? d) "Hello, World!'

a) `strip()` 17. What is the result of `"Python"[1:4]`?

b) `trim()` a) "Py"

c) `remove_whitespace()` b) "yth"

d) `clear()` c) "tho"

13. Which method can be used to find the index d) "Pyt"


of the first occurrence of a substring within a
string? 18. Which of the following methods can be used
to replace all occurrences of a substring in a
a) `find()` string with another substring?

b) `search()` a) `replace()`

c) `index()` b) `sub()`

d) `locate()` c) `swap()`

14. Which of the following is not a valid way to d) `insert()`


concatenate strings in Python?
19. How do you check if a string contains only
a) Using the `+` operator alphabetic characters (letters)?

b) Using the `concat()` method a) `isalpha()`

c) Using f-strings b) `isnumeric()`

d) Using the `.join()` method c) `isdigit()`

15. What does the `split()` method in Python do? d) `isalnum()`

a) Splits a string into a list of substrings based 20. Which of the following methods can be used
on a delimiter to check if a string ends with a specific suffix?

b) Combines two strings into one a) `end_with()`

c) Removes all whitespace from a string b) `is_endswith()`

d) Converts a string to lowercase c) `endswith()`


d) `has_suffix()` d) Error

JAVA MCQ QUESTIONS: 5. How can you find the length of a string in
Java?
1. In Java, which class is used to represent
strings? a) `str.length()`

a) String b) `str.size()`

b) StringBuilder c) `str.length`

c) StringBuffer d) `str.size`

d) CharSequence 6. Which method can be used to convert a string


to all uppercase letters in Java?
2. What is the difference between `String` and
`StringBuilder` in Java? a) `toUpper()`

a) `String` is mutable, while `StringBuilder` is b) `toUpperCase()`


immutable.
c) `uppercase()`
b) `String` is faster for string manipulation
than `StringBuilder`. d) `capitalize()`

c) `String` is a final class, while 7. In Java, can you change the characters of a
`StringBuilder` is not. `String` after it has been created?

d) `String` cannot be used for text processing. a) Yes

b) No

3. Which method is used to compare two strings 8. What is the default value for a `String`
in Java for their content? variable in Java if it is not initialized?

a) `equals()` a) null

b) `compareTo()` b) ""

c) `compare()` c) "null"

d) `contentEquals()` d) "undefined"

9. Which method can be used to extract a


substring from a given string?
4. What is the result of
`"Hello".concat("World")` in Java? a) `subString()`

a) "HelloWorld" b) `slice()`

b) "Hello World" c) `getSubstring()`

c) "WorldHello" d) `substring()`
10. How do you check if a string contains a d) `replaceLast()`
specific substring in Java?
15. How do you concatenate two strings in Java?
a) `str.contains(substring)`
a) Using the `&` operator
b) `str.indexOf(substring) != -1`
b) Using the `+` operator
c) `str.includes(substring)`
c) Using the `concat()` method
d) `str.find(substring)`
d) Using the `join()` method
11. What is the result of `"Java".charAt(2)`?
16. What is the output of
a) 'J' `"java".toUpperCase()`?

b) 'a' a) "java"

c) 'v' b) "JAVA"

d) 'a' c) "Java"

12. Which method can be used to check if a d) "jAVA"


string starts with a specific prefix?
17. How do you check if a string ends with a
a) `startsWith()` specific suffix in Java?

b) `beginWith()` a) `str.ends_with(suffix)`

c) `startWith()` b) `str.is_endswith(suffix)`

d) `prefixWith()` c) `str.endsWith(suffix)`

13. How can you convert an integer to a string in d) `str.hasSuffix(suffix)`


Java?
18. Which method can be used to trim leading
a) `String.valueOf(intValue)` and trailing whitespace from a string in Java?

b) `intValue.toString()` a) `trim()`

c) `intValue.to_string()` b) `strip()`

d) `toString(intValue)` c) `clean()`

14. Which method can be used to replace all d) `removeWhitespace()`


occurrences of a substring in a string with
another substring? 19. What is the result of `"Java".substring(1,
3)`?
a) `replace()`
a) "Jav"
b) `replaceAll()`
b) "ava"
c) `replaceFirst()`
c) "av"
d) "va"

20. Which method can be used to count the


number of non-overlapping occurrences of a
substring within a string in Java?

a) `count()`

b) `find()`

c) `indexOf()`

d) `matches()`

BASIC CODING QUESTIONS(SOLVE IN


BOTH PYTHON AND JAVA)

1. Addition of two numbers (read input from

user)

2. Program to whether a given year is leap

year or not

3. Program to check whether a given

number is positive or negative

4. Program to find square root of a number

5. Write a program to find the given

number is perfect square or not?

6. Write a program to find addition of three

numbers (read 3 integers from user)

You might also like