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: Noob needs help!

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Noob needs help!

    accepts two strings and returns the character index of the position
    where the second string begins in the first; returns -1 if the second string does not appear in the first.

    Examples:
    IN: mississippi ss OUT: 2
    IN: superlative zzl OUT: -1





    public class Test {
    	public static void main(String[] args) {
    		String s1 = "mississippi";
    		String s2 = "s";
    		System.out.print(findInStr(s1, s2));
    	}
    	public static int findInStr(String s1, String s2) {
    		char c =(char) s2; 
    		if( s1.substring(1, s1.length()-1) == c ) {
    			return s1.indexof(c);
    		}
    		else{
    			return -1;
    		}	
    	}
    }
    Last edited by Freaky Chris; November 2nd, 2011 at 05:04 AM.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Noob needs help!

    Hi Kram,

    Could I please request you read the following.

    http://www.javaprogrammingforums.com...-get-help.html

    Then re-consider your questioning.

    Thanks,
    Chris

Similar Threads

  1. NOOB: Array Help
    By DEAF in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 30th, 2011, 08:39 PM
  2. Total NOOB question
    By coolidge in forum Java Theory & Questions
    Replies: 3
    Last Post: September 2nd, 2011, 04:09 PM
  3. Programming noob here, need help!
    By artenuga54 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2010, 04:04 PM
  4. helloworld noob
    By LostFury2012 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 14th, 2010, 06:29 AM
  5. Need Help with my hmwk! Java noob!
    By ravij in forum Loops & Control Statements
    Replies: 4
    Last Post: October 7th, 2009, 01:02 AM