• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

String Program Help

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 35
Netbeans IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Marshal
Posts: 73266
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic