
15.string s= "Я люблю программировать!!!"; int p =s.LastIndexOf("");
Console.WriteLine(p);16. string s= "Я люблю программировать!!!"; string res=s.Remove(27); Console.WriteLine(res);17. string s= "Я люблю программировать!!!"; string res=s.Substring (5); Console.WriteLine (res);18. string s= "Я люблю программировать!!!"; int p = s.IndexOf ("Я", -5); Console.WriteLine(p);20. string s= "Я люблю программировать!!!"; int p = s.LastIndexOf('в', 10, -6); Console.WriteLine(p);Определить что будет напечатано в результате выполнения фрагмента программы!!!

Ответы на вопрос

Code Analysis
Let's analyze each line of code to determine what will be printed as a result of executing the program:
15. `string s = "Я люблю программировать!!!";` - This line initializes a string variable `s` with the value "Я люблю программировать!!!".
16. `int p = s.LastIndexOf("");` - This line assigns the value of the last index of an empty string in `s` to the integer variable `p`. - The `LastIndexOf` method returns the index position of the last occurrence of the specified string within the current string, or -1 if the string is not found.
17. `string res = s.Remove(27);` - This line removes all characters from the string `s` starting from index 27 and assigns the result to the string variable `res`. - The `Remove` method removes a specified number of characters from a string, starting at a specified position.
18. `string res = s.Substring(5);` - This line assigns a substring of `s` starting from index 5 to the string variable `res`. - The `Substring` method returns a new string that is a substring of the current string, starting from the specified index.
19. `int p = s.IndexOf("Я", -5);` - This line assigns the index of the first occurrence of the string "Я" in `s`, starting from index -5, to the integer variable `p`. - The `IndexOf` method returns the index position of the first occurrence of the specified string within the current string, or -1 if the string is not found.
20. `int p = s.LastIndexOf('в', 10, -6);` - This line assigns the index of the last occurrence of the character 'в' in `s`, starting from index 10 and searching up to index -6, to the integer variable `p`. - The `LastIndexOf` method returns the index position of the last occurrence of the specified character within the current string, or -1 if the character is not found.
Result of Executing the Code
Based on the analysis of the code, here's what will be printed as a result of executing the program:
15. No output will be printed since this line only initializes the string variable `s`.
16. No output will be printed since the value of `p` is not printed.
17. The output will be: "Я люблю программировать!!!". - This is because the `Remove` method removes all characters from the string `s` starting from index 27, but since the string length is less than 27, no characters are removed.
18. The output will be: "юблю программировать!!!". - This is because the `Substring` method returns a new string that starts from index 5 of `s`, which is "юблю программировать!!!".
19. The output will be: 0. - This is because the `IndexOf` method searches for the first occurrence of the string "Я" in `s`, starting from index -5. Since the starting index is negative, it is treated as 0, and the first occurrence of "Я" is found at index 0.
20. The output will be: -1. - This is because the `LastIndexOf` method searches for the last occurrence of the character 'в' in `s`, starting from index 10 and searching up to index -6. Since the starting index is greater than the ending index, no character is found, and -1 is returned.
Please let me know if you need any further clarification!


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili