• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Need help with this array

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I'm working on an array on Java and I need it's really confusing me.
I have to input last names using the dialog box and store them into an array. Then take that array, loop through it to get the last character of the last name and the next to last and capitalize those characters.
Example "Smith" should return H. S. Smith, then store the new formatted names into an array and return that array.
I've created two classes



This isn't completed yet, but so far it doesn't work. So please, I don't want the answer right away to this problem but an understandable way to do this so I can get it.
=-)
 
Bartender
Posts: 11226
91
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't look at the whole thing but your first call to substring() passes in the length of the array not the length of the name.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Reem Akira wrote:I have to input last names using the dialog box and store them into an array. Then take that array, loop through it to get the last character of the last name and the next to last and capitalize those characters.
Example "Smith" should return H. S. Smith, then store the new formatted names into an array and return that array.


In your example, shouldn't "Smith" return "T. H. Smith" because capitalize last character (H) and the next to last (T) of the last name?


 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Reem, welcome to the ranch.

You didn't quite get the code tags right in your post so I have added them properly for you. You need to highlight the code before clicking the code tags button. If you are still not sure you can read the tutorial on how to UseCodeTags.
 
Reem Akira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Docherty wrote:Hi Reem, welcome to the ranch.

You didn't quite get the code tags right in your post so I have added them properly for you. You need to highlight the code before clicking the code tags button. If you are still not sure you can read the tutorial on how to UseCodeTags.



Thank you.
 
Reem Akira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:Welcome to the Ranch.

Reem Akira wrote:I have to input last names using the dialog box and store them into an array. Then take that array, loop through it to get the last character of the last name and the next to last and capitalize those characters.
Example "Smith" should return H. S. Smith, then store the new formatted names into an array and return that array.


In your example, shouldn't "Smith" return "T. H. Smith" because capitalize last character (H) and the next to last (T) of the last name?




Yes, indeed it is "T. H. Smith" That was a typo. Other thing is that I decided to use an initializer list instead of having an user inputting the names, to make it easier. Though my code still doesn't work. The output is ....not what I expected
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so write out exactly what you would do if you were doing it yourself before writing any code. ie:

Read the last letter in the name.
Convert it to upper case
Write it down
Write down a full stop
Read the second from last letter in the name.
Convert it to upper case
Leave a space and write it down
Write down a full stop

I'll leave you to finish this off.
 
reply
    Bookmark Topic Watch Topic
  • New Topic