-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask1.java
More file actions
25 lines (22 loc) · 1.11 KB
/
Task1.java
File metadata and controls
25 lines (22 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Work01.Unit02;
public class Task1 {
/**
* Задание 1
* Напишите метод, который принимает на вход строку (String)
* и определяет является ли строка палиндромом (возвращает boolean значение).
*/
// public static boolean isPalindrome(String text) {
// text = text.replaceAll("\\W","");//удаляем все ненужное
// StringBuilder strBuilder = new StringBuilder(text);
// strBuilder.reverse(); //переворачиваем строку
// String invertedText = strBuilder.toString();//присваиваем перевернутую строку
//
// return text.equalsIgnoreCase(invertedText) ;//возвращаем сравнение двух строк вне зависимости от регистра
//
// }
public static boolean isPalindrome(String text) {
return text.replaceAll("\\W","")
.equalsIgnoreCase(new StringBuilder(text.replaceAll("\\W",""))
.reverse().toString());
}
}