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 2 of 2

Thread: Need help with what I think should be a for loop

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with what I think should be a for loop

    Hello everyone!
    I am new to Java and I am trying to learn it by myself along with taking a class for it.
    I have a question about strings
    I am trying to write a small program that takes two strings from using input (lets call them String a and String b) and compare them.
    An example of how I am trying to compare would be:
    String a= CATSATONTHEMAT String b= AT and I need to output to be how many times "AT" appears in String a
    Is that the string compare function? I have tried setting up a for loop with a counter, but was unsuccessful. Am I on the right track with this?
    I do not want someone to just give me code that works, just some suggestions that might help me get to the correct line of thinking.
    Any help would be awesome

    Thank you


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,613
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Need help with what I think should be a for loop

    What String class methods have you tried? Look at the String class's indexOf method.


    Also posted at: http://www.java-forums.org/new-java/62807-strings.html
    Last edited by Norm; September 7th, 2012 at 01:15 PM.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Please help with my while loop that turned into infinite loop!
    By Hazmat210 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 10th, 2012, 10:22 PM
  2. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 07:57 PM
  3. For loop; Problems with my for loop
    By mingleth in forum Loops & Control Statements
    Replies: 5
    Last Post: November 16th, 2011, 06:24 PM
  4. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 02:09 AM
  5. hi. i want to rewrite this do loop into a while loop.
    By etidd in forum Loops & Control Statements
    Replies: 3
    Last Post: January 26th, 2010, 04:27 PM