• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting the number in user input  RSS feed

 
Eneria Reign
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Sankalp Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coding tip: it's a strong convention that variables start with lower-case letters.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • 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?
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • 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: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't go anywhere near nextLine until you understand the problem discussed in this old post.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!