String s = "string";
String s1 = "";
String s2 = "";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != ' ') {
s1 += s.charAt(i);}}
System.out.println(s1);
for (int i = s1.length() - 1; i >= 0; i--) {
s2 += s1.charAt(i);}
System.out.println(s2);
if (s1.equalsIgnoreCase(s2)) {
System.out.println("Palindrome");
} else {
System.out.println("Fail"); }}}
6. If a letter is in the given string, put it into brackets. Tere e ->
T(e)r(e)
List
Sõneliteraal char[] tähed = {'a','b','c'}; char[] tähed2 = {'a','b','c'}; String sõne1 = new String(tähed); String sõne2 = new String(tähed2); String sõne3 = "abc"; String sõne4 = "abc"; false System.out.println(sõne1 == sõne2); false System.out.println(sõne1 == sõne3); True System.out.println(sõne3 API == compareTo, equals, equalsIgnoreCase, indexOf, length, replace, võrdlus meetodid charAt, sõne4); toLowerCase, toUppercase, toString Meetod, mis tuvastab palindroomi static boolean onPalindroom(String s) { int algusest = 0; //esimene märk int lõpust = s.length() - 1; //viimane märk while (algusest < lõpust) { if (s.charAt(algusest) != s.charAt(lõpust)){ return false; // ei ole palindroom } algusest++; lõpust--; }