Question: Background Java String class. Reading input till end of file: You can use scanner methods like hasNextLine() or hasNext() in a while loop like this:

Background
Java String class.
Reading input till end of file: You can use scanner methods like hasNextLine() or hasNext() in a while loop like this:
final Scanner stdin = new Scanner(System.in, "US-ASCII");
while (stdin.hasNext()) {
final String s = stdin.next();
}
Differences between next() and nextLine() methods in Java.
The Task
Given a string of letters find the minimum number of letters you have to remove from the string, so that a reordering of the letters will result in a palindrome. A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.
Input
All input is read from the standard input stream. The input consists of any number of strings. The strings will contain a least 1 and at most 1000 characters, and will contain only lowercase letters 'a' through 'z'.
Output
All output is written to the standard output stream. Each line of the output consists a single decimal integer, one for each string in the input.
Sample
Sample input:
abc add
The corresponding output:
2
0
In the first case removing "bc" leaves the palindrom "a". And in the second case reordering "add" yields the palindrom "dad".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!