Skip to content
Advertisement

Tag: string

Find the first Recurring letter in Java

I wrote the code as follows but it doesn’t return the first recurring letter properly. Example: In the word “statistics” the recurring letters are s, t, and i. But the letter t recurs sooner than the letter s and i, but my program returns s instead of t. What do I need to do for it to return t, using

Doubling one letter with each new occurence

so I have task to double number of letter “a” every time it occurs in a string. For example sentence “a cat walked on the road” , at the end must be “aa caaaat waaaaaaaalked on the roaaaaaaaaaaaaaaaa” . I had something like this on my mind but it doubles every charachter, not only “a”. Answer You need to check

why can’t I add chars to a new string?

code: The second line is wrong for some reason and I don’t know why Answer The book is wrong, and Eclipse is right. In Java, you can write “abc” + whatever, or whatever + “abc”, and it concatenates the strings — because one side is a String. But in st.charAt(0)+st.charAt(st.length()-1)), neither side is a String. They’re both chars. So Java

Advertisement