Dipanjan Pramanik wrote:A bluej java program to print the position of the character which has double letters......
Example: Little star shinning bright
It is tt and nn
here is my program:
static void main() throws IOException
BufferedReader obj= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input a String");
String s= obj.readLine();
System.out.println("The chars to check:"+s.charAt(i)+" "+s.charAt(i+1));
if( s.charAt(i)== s.charAt(i+1))
System.out.println("The position of the character is:"+(s.indexOf(s.charAt(i+1))));
Dipanjan, use available data structures, put it in a Map<Char, Integer>, get the stream of that and use a lambda to get at a Collection<Char> with the condition that the Integer in that Map would be > 1, something like that. Or use loops. But definitely use a Map<Char, Integer>.
Then, loop through the char array of that String and make another Map<Char, List<Integer>> and add to that list when you encounter that char...
You will end up with a Map that has a Char key and a List of its locations with the String you're parsing.
You can then use that data for further analysis on these chars.
With best regards,
Anton Golovin (firstname.lastname@example.org) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]