• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting the number in user input

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! i need lil help please

we were instructed to get a user input for his/her full name and address to make an ID out of it

example:
Name: Eneria De Reign
Address 09 coderance

output : EDR09
(first Letter of his/her name + number in the address)

my code so far.. i separated the First name to last name because i dont know how to get the Initial Letters if the code asks for Full name in one input
my prob is the address i need the number out of it xD



thanks in advance
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

First, please UseCodeTags (that's a link) when you post code. I'll do it for you this time.

Do you know about String#split? You can split by a space and get a String[] array.

Try getting the whole name and then splitting, then we can refine the code if necessary.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you take full name, instead of taking first name and last name separately,

indexOf() method might be helpful. You just have to write a small logic for getting first name's first letter and last name's first letter.

There are 4 overloaded indexOf() methods. You can use them according to your need.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Coding tip: it's a strong convention that variables start with lower-case letters.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

I thought I was adding the code tags Doesn't it make your code look better, but the indentation is inconsistent. That might be to do with which editor you are using: make sure it supports automatic indentaiton and don't use plain NotePad.
Is there anything wrong with the code you posted? What sort of output do you get?
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't use to get the address, since it will only get the next token, not the entire address; you should use nextLine() instead. However, in your particular case it would seem to work, since it will get the number by itself. Also, your code only asks for first and last names. What about the middle name required by the instructions? What happens if the user types in "De Reign" for the last name? Your code will only return "De" and then will get "Reign" as the address.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't go anywhere near nextLine until you understand the problem discussed in this old post.
reply
    Bookmark Topic Watch Topic
  • New Topic