Results 1 to 6 of 6
  1. #1
    toaster_man is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default Java String Digit Question

    Hey guys im having a bit of trouble here, im not really sure what to do.
    So i need to make a method which checks these requirements:

    String must have at least eight characters.(Done)
    String consists of only letters and digits.
    String must contain at least two digits

    any idea?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Check each of the characters one by one in a for loop. There are some Character isXXX() methods that are useful.

  3. #3
    toaster_man is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    im not sure how to do that

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Obtaining an array of all the characters in a String: use the String toCharArray() method

    Using a for loop to check each element of an array: The for Statement in Oracle's Tutorial

    The early sections of the Tutorial also explain a lot of basic Java syntax and usage.

    -----------------------------

    im not sure how to do that

    Break the problem into parts rather than trying to write the program all at once.

    * Write some code to obtain an array of characters from a string
    then
    * Write some code to print the characters one at a time on separate lines
    then
    * Think about which of the Character methods are useful, and how you would use them to check the string
    then
    * Write some code to implement the plan you have for checking the string

    It's hard to offer specific advice without knowing what you have read and what you have tried. So, post code. If it won't compile and you can't understand the compiler message copy and post that message. If the code compiles and runs but doesn't do what you intend say what it does do.

  5. #5
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Another way would be to work with regular expression, have you already experience with it?
    Pattern (Java Platform SE 6)

  6. #6
    toaster_man is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. select a digit in a number
    By navid in forum New To Java
    Replies: 3
    Last Post: 12-12-2010, 10:47 AM
  2. int[] with multi-digit values: toString()
    By soccermiles in forum New To Java
    Replies: 8
    Last Post: 04-27-2010, 01:30 PM
  3. digit spacing
    By puk284 in forum New To Java
    Replies: 3
    Last Post: 06-09-2009, 02:49 PM
  4. Locating a digit within a string
    By ScentOfAWookie in forum New To Java
    Replies: 8
    Last Post: 03-27-2009, 05:23 PM
  5. Java newb Q: 8-digit id
    By 1111FM in forum New To Java
    Replies: 2
    Last Post: 09-29-2008, 02:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •