import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
char[] sArray;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a Palindrome : ");
String s = scan.nextLine();
sArray = new char[s.length()];
for(int i = 0; i < s.length(); i++)
{
s.toLowerCase();
sArray[i] = s.charAt(i);
System.out.print(sArray[i]);
}
}
}
It doesn't work because strings are immutable. You need to reassign: s = s. toLowerCase();
Java String toLowerCase() method is used and operated over string where we want to convert all letters to lowercase in a string. There are two types of toLowerCase() method as follows: toLowerCase() toLowerCase(Locale loc): Converts all the characters into lowercase using the rules of the given Locale.
Java - toLowerCase() Method The method returns the lowercase form of the specified char value.
It doesn't work because strings are immutable. You need to reassign:
s = s.toLowerCase();
The toLowerCase()
returns the modified value, it doesn't modify the value of the instance you are calling this method on.
You need to do:
String newStr = s.toLowerCase();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With