Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: New to Java and not sure how to start my assignment using scanner, length method, and substring method

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    My Mood
    Cheerful
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default New to Java and not sure how to start my assignment using scanner, length method, and substring method

    note: I have not taken any cpu/java classes besides the one I am currently enrolled in. I am currently in a computer science 101 class for java. I am not asking for you to do my homework assignment for me, but to help me get started/understand. Thank you.

    My assignment is to ask the user to enter a string
    Then to display the length of their string, as well as to ask which numbers they want to look between.
    After they enter which numbers they want to look between, it must then display what words/letters are within those 2 numbers.

    Example:
    Enter a string:
    I love coffee

    The length of the string is: 13
    Enter the numbers you want to look between
    2
    5


    The part of the string between 2 and 5 is: love



    My instructor hinted that we will be using scanner, length method, and substring method


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: New to Java and not sure how to start my assignment using scanner, length method, and substring method

    Hi,

    post your code and ask specific questions. It's hard to help you without knowing where you are stuck. Break the assignment down to small bits, start with getting the user input. Read the API docs your instructor has mentioned.

  3. The Following User Says Thank You to PhHein For This Useful Post:

    JavaNewbie14 (October 2nd, 2014)

  4. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    My Mood
    Cheerful
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: New to Java and not sure how to start my assignment using scanner, length method, and substring method

    this is what i have so far. now how do i use the substring method so that the user can input 2 integers and then display the part of the string between those 2 integers?



    import java.util.Scanner;
     
    class Strings
    {
         public static void main(String[] args)
         	{
    			System.out.println("Enter a string, then hit enter.");
     
    		 	Scanner keyboard = new Scanner(System.in);//Scanner is titled keyboard
    		 	String userString = keyboard.nextLine();//String inputed by user is titled userString
    			int count = userString.length();
    			System.out.println("\nYour string has a length of " + userString.length() + ". Enter the numbers you want to look between.");
     
    		}
    }
    Last edited by JavaNewbie14; October 2nd, 2014 at 04:16 AM.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: New to Java and not sure how to start my assignment using scanner, length method, and substring method

    Have you read the String API to see how to use the substring() method? Start there.

  6. The Following User Says Thank You to GregBrannon For This Useful Post:

    JavaNewbie14 (October 2nd, 2014)

  7. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    My Mood
    Cheerful
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: New to Java and not sure how to start my assignment using scanner, length method, and substring method

    thank you, i was able to figure it out

Similar Threads

  1. Beginner Question length method
    By Johnathanrs in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 28th, 2014, 03:43 PM
  2. Reading Text Files Assignment [Scanner Method]
    By iAce in forum What's Wrong With My Code?
    Replies: 8
    Last Post: December 9th, 2012, 10:41 PM
  3. Substring Retrieval Method Question
    By Nuggets in forum Java Theory & Questions
    Replies: 12
    Last Post: January 31st, 2012, 12:16 AM
  4. text.length method problem?
    By computercoder in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 3rd, 2010, 10:40 AM
  5. Replies: 1
    Last Post: February 4th, 2010, 04:23 PM