Results 1 to 5 of 5
  1. #1
    7ala_07 is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default can anyone help me?

    hi

    i'm a new one here :)

    My teacher asked us to research this on the net

    the question is about a function in java like ( next.Int(); )
    the function read string text and stop when it's a white space !!

    can u plz help me to find it ,,


    thanx anyway

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Scan this and that...

    As far as I know (which may not be much), there is no method next.Int(). There is a method nextInt() from the Scanner class:
    Scanner (Java Platform SE 6)
    Maybe you can find what you're looking for there.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    mostafa-sky is offline Member
    Join Date
    Mar 2009
    Location
    Yemen - Taiz
    Posts
    5
    Rep Power
    0

    Default

    if u mean nextInt()
    there are more than one else
    it could be the member function of java.util.Random class

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    there are more than one else
    it could be the member function of java.util.Random class
    Mostafa... I didn't understand the above. Did you answer in the correct post, because I can't find the link between your response and the subject of the post.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    It sounds like you want to use trim()... That is the built in version of what you are looking for... For instance if you are reading a string from a file and the the text in the file is:
    Java Code:
    SomeText          \n
    Notice the "\n" is 10 spaces after the last letter... The "\n" represents the end of the line... If you were trying to compare this to "SomeText" it would not match... So you will need to trim the white space... If you had to make your own you would probably have to do something like this:

    Java Code:
    public String myTrim(String text) {
    
            StringTokenizer st = new StringTokenizer(text, " ", false);
            String t = "";
    
            for (int i = 0; i < st.countTokens(); i++) {
                t += st.nextElement();
            }
    
    
            return t;
    
        }

Posting Permissions

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