• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Program Help  RSS feed

 
Gabriel Belmont
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just can't figure out the faulty behaviour of my code.Tried my level best to fix it but still no progress.Whenever I give input string say like "Something Something(Tutorial)",I expect my code to produce "SS(T)".It does generate "SS(T)" but there appears to be huge space between SS and (T).Can anyone please tell me what is causing this anomaly?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gabriel Belmont wrote:I just can't figure out the faulty behaviour of my code.Tried my level best to fix it but still no progress.Whenever I give input string say like "Something Something(Tutorial)",I expect my code to produce "SS(T)".It does generate "SS(T)" but there appears to be huge space between SS and (T).Can anyone please tell me what is causing this anomaly?

I had to reformat your code in order to read it.

I'm not sure what we are doing differently, but it works for me:

Perhaps you can copy/paste your command line output so we can see what I are doing differently to you?
 
Jacob Draper
Ranch Hand
Posts: 35
Java Linux Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was getting the spaces myself. If you notice, the array you are creating is of length 75. Count the spaces and maybe you will see it's the same? Maybe you are converting that entire array to a String (including those elements that are blank). Change that array to something else say 25 and see what you get!

Hopefully that points you in the right direction.

Also, I agree with Andrew as far as formatting. A few returns and indentations could make it much easier for others to read your code. I didn't get crazy but at least put gaps between your methods So it didn't all just look like one big block.
 
Gabriel Belmont
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Monkhouse wrote:
I had to reformat your code in order to read it.

I'm not sure what we are doing differently, but it works for me:

Perhaps you can copy/paste your command line output so we can see what I are doing differently to you?


I am sorry.I just started my java Programming.I will try to cultivate some good programming styles.Now coming to my code,here is my command line output.Please take a look

prob.png
[Thumbnail for prob.png]
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That picture is illegible. Andrew said copy and paste. You can find out how to copy text from a Windows® command line here. When people can read your text, then they can help you.
 
Gabriel Belmont
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Draper wrote:I was getting the spaces myself. If you notice, the array you are creating is of length 75. Count the spaces and maybe you will see it's the same? Maybe you are converting that entire array to a String (including those elements that are blank). Change that array to something else say 25 and see what you get!

Hopefully that points you in the right direction.

Also, I agree with Andrew as far as formatting. A few returns and indentations could make it much easier for others to read your code. I didn't get crazy but at least put gaps between your methods So it didn't all just look like one big block.


Thanks.What you said was right.The problem is due to array length.Resolved it myself.Cheers!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!