Hot answers tagged

8 votes

Reverse string with identical spaces as in original String using Java

You can make a String directly from a character array. So ...
user avatar
  • 20.5k
4 votes

Reverse string with identical spaces as in original String using Java

I suggest you rely on StringBuilder. That way, appending to it runs in amortized constant time. I had in mind the following implementation: ...
user avatar
  • 25.7k
2 votes

Calculate square of (sum of even-indexed) - (sum of odd-indexed) subarrays from an array

This problem can be treated as a candidate for Kadane's algorithm after odd indexed elements are negated. Original array A = [1,2,-1,4,-1,-5] negate odd indexed elements B = [1,-2,-1,-4,-1,5] Once ...
user avatar
  • 21
2 votes

Reverse string with identical spaces as in original String using Java

You can use IntStream.range() to get the indices of spaces. ...
user avatar
2 votes

Reverse string with identical spaces as in original String using Java

I think I would do it like this: ...
user avatar
2 votes
Accepted

Using methods to get and display userInput

numberEntered should not be static and should not be a member. It's good that you made a variable for quit, but it should be ...
user avatar
  • 49.5k
1 vote
Accepted

Task executor thread pool

I am assuming this is not intended for serious use, as there’s no good reason not to use the tools already provided by Java for pooling threads made available in Executors. As I am not an expert in ...
user avatar
  • 6,211
1 vote

Reverse string with identical spaces as in original String using Java

You don't need all that much to do this. Both the OP's solution and @coderodde's seem overworked with too many extraneous objects. One StringBuilder is needed for ...
user avatar
  • 1,302

Only top scored, non community-wiki answers of a minimum length are eligible