Results 1 to 4 of 4
  1. #1
    jigglywiggly is offline Senior Member
    Join Date
    Nov 2008
    Posts
    105
    Rep Power
    0

    Default Does this seem right?

    This was the question
    e) Write a loop that prints to the screen the last letter in each string stored in a String array named stringArray starting with the first String in the array and ending with the last. (Example: if stringArray = {“Hello”, “my”, “name”, “is”, “Bob”} your loop should print

    So I just want to double check, if my answer seems right.
    Java Code:
    int j = stringArray.length; 
    for(int i=0; i<j; i++) {
    String last = stringArray.[i](stringArray[i].length()-1);System.out.println(last);
    }
    Thanks
    Last edited by jigglywiggly; 01-22-2009 at 08:19 AM.

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

    Default

    Have you compiled it? Did you get the desired output?

    CJSL
    Last edited by CJSLMAN; 01-22-2009 at 08:50 AM. Reason: I misunderstood the OPs post...
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    jigglywiggly is offline Senior Member
    Join Date
    Nov 2008
    Posts
    105
    Rep Power
    0

    Default

    Nope, no compiler with me and I'm on the go, just tethered my phone to my lappy, too slow to download netbeans etc. I just wanted confirmation :o

  4. #4
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    String last = stringArray.[i](stringArray[i].length()-1);System.out.println(last);
    I guess that to get just one letter you can use charAt()
    char last =stringArray[i].charAt(stringArray[i].length-1);
    System.out.println(last);

Posting Permissions

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