2 Replies - 13883 Views - Last Post: 05 February 2009 - 12:47 PM Rate Topic: -----

#1 kikee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 05-February 09

Word length Check

Post icon  Posted 05 February 2009 - 04:17 AM

Hey Guys,

i have a problem checking the length of some words in java.

the idea is, that you will have a name and id, so for example:
Name: james Johnson
ID: 0808855

the program should take the first 4 letters of james and the first 3 of the ID - which works :D

but, when there are only 3 characters in the name, i need a rule to print an error message if the name is less than 4 characters or id is less than 3! as you will see below, im a complete beginner and any help is appreciated

public String getLoginName()
{
if (name (<4));
System.out.println("There are too few letters in your name");
if (ID (<3));
System.out.println("There are too few letters in your ID");
return name.substring(0,4) + id.substring(0,3);
}

Is This A Good Question/Topic? 0
  • +

Replies To: Word length Check

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Word length Check

Posted 05 February 2009 - 04:26 AM

please do NOT double post!
and use code tags when adding code: :code:
your question is answered here: http://www.dreaminco...wtopic84806.htm thanks....
Was This Post Helpful? 0
  • +
  • -

#3 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Word length Check

Posted 05 February 2009 - 12:47 PM

the length() method
if(name.length() < 4);


the length() method returns how many letters are in the string
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1