Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    hhhmmm... I don't think your program is working the way it should...
    I got it, when i went to go to input it in, i put underscores in like
    The_Lord_of_the_Rings and i got all the answers i needed.
    the above only inidcates that you have changed the input to meet the desired output.
    For it to work, you need to change:
    Java Code:
    String myStr = keyboard.next();//this only reads to the first blank
    to
    Java Code:
    String myStr = keyboard.nextLine();//this reads the whole line
    I'm still thinking about the date requirement.

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

  2. #22
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    They probably want you to look up and learn about the Date class and the DateFormat class.
    Check out the Date class and the DateFormat Class.

    Hope those work out.

    Mr.Beans
    Last edited by Mr.Beans; 04-10-2009 at 03:08 AM. Reason: Added links

  3. #23
    osufeth24 is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default

    now when i made those changes, it says the length is 0

    PHP Code:
    System.out.println("Enter a string of characters: ");
    		String myStr = keyboard.nextLine();
    		System.out.println("The length of string  \"The Lord of the Rings\" is " + myStr.length());
    this is what i have, is there something in the coding that's not making it read properly?
    Last edited by osufeth24; 04-10-2009 at 03:06 AM.

  4. #24
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    You need to change your part where you get the String to
    Java Code:
    // string test
            System.out.println("*** Test String operations ***\n");
            System.out.println("Enter a string of characters: ");
            keyboard.nextLine();    // eat up the new line
            String myStr = keyboard.nextLine(); // get the next new line
            // print out length
            System.out.println("Your string was " + myStr.length() + " characters long");
    As for the Date part you should try to make your own code and see what you can come up with. It will help you in the long run.
    We're not here to do your homework for you. We're here to help you learn Java.

  5. #25
    osufeth24 is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default

    got it now, i had it backwards.

    I know, and i want to learn, i just wasn't sure of what some of the commands were, and what i needed to put, that's all.

    I really appreciate the help though from you guys. I'm just one of those guys that kinda has to see how it's done first to be able to understand it. I'll keep trying to chug away at this date thing

    Thanks again!!
    Last edited by osufeth24; 04-10-2009 at 04:23 AM.

  6. #26
    osufeth24 is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default

    I think i might be close with the dates
    PHP Code:
    System.out.println("*** One last test ***\n");	
    		System.out.println("Enter your birthday (mm/dd/yyyy): ");
    		keyboard.nextLine();
    		String szDate1 = "10/25/1983";
    		String szDate2 = szDate1.substring(3,4) + "-" + szDate1.substring(0,1) + "-" + szDate1.substring(6,9);
    there's something with the szDate2 thats wrong

    the error says The local variable szDate2 is never read

    ok duh, i forgot the System.out.println part

    but it looks like my substring numbers are off because the output is 2-1-198

    and it should read 25-10-1983

    i finally got it, i had to bump the 2nd number in each () up one, it's pretty satisfying when it all comes out correctly..

    Thanks for help guys!
    Last edited by osufeth24; 04-10-2009 at 05:19 AM.

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

    Default

    osufeth24... if you read the API for substring(int beginIndex, int endIndex), it indicates:
    The substring begins at the specified beginIndex and extends to the character at index endIndex - 1
    String substring(int,int) (Java Platform SE 6)

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

Page 2 of 2 FirstFirst 12

Similar Threads

  1. how to store string in text file
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-03-2009, 06:21 AM
  2. How to write a string middle of a text file?
    By loggen in forum New To Java
    Replies: 5
    Last Post: 12-19-2008, 08:48 AM
  3. Searching a string from a text file using Swing Buttons
    By pradeep1_mca@yahoo.com in forum AWT / Swing
    Replies: 2
    Last Post: 09-15-2008, 09:50 AM
  4. Searching a String from Text file using Swings .
    By pradeep1_mca@yahoo.com in forum AWT / Swing
    Replies: 4
    Last Post: 09-09-2008, 05:29 AM
  5. Replies: 1
    Last Post: 01-11-2008, 10:06 PM

Posting Permissions

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