Page 1 of 2 12 LastLast
Results 1 to 20 of 21
Like Tree6Likes

Thread: About strings!!!! reposted with update ;)

  1. #1
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Exclamation About strings!!!!!!! HELP ME!!!!!!

    so the goal of this code is to test if the big string contains a small string. like "the cat in the hat." and we are trying to test if "cat" is in the sentence.
    this is what i have :
    my question is what do i put in the if statement?/what methods should i use?

    Java Code:
    public class MoreStrings {
    
        public static boolean givenString(String input) {
    
            char[] words = input.toCharArray();
    
            boolean result = true;
    
            for (int i = 0; i < words.length; i++) {
              
                    if () {
                    
                    }
                        
                }
            return result; } 
    
           
        
    
        public static void main(String[] args) {
    
            String input1 = "abcdef ghi jklmn";
            String input2 = "ghi";
            boolean ret = givenString(input1);
            if (ret == true) {
    
                System.out.println(true);
            } else {
    
                System.out.println(false);
            }
            
        }
    }
    Last edited by HelpingIsCaring; 06-28-2013 at 07:32 PM.

  2. #2
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    *Deleted* upon request
    Last edited by HelpingIsCaring; 06-28-2013 at 07:28 PM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    Please go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    I also suggest that you read and take to heart the recommendations in How to ask questions the smart way

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    Also, if you haven't read it already:

    String (Java Platform SE 6)

    There's a method in the String class that does pretty much exactly what you want.

  5. #5
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    Java Code:
    String string = "hey, I am allaudin";
    		String toFind = "allaudin";
    		int result = string.indexOf(toFind);
    		if(result == -1)
    			System.out.println("Not found");
    		else
    			System.out.println("Found");
    thats how you can do it

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    732
    Rep Power
    2

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    @helpiscaring The more exlamation marks you add, the less people are inclined to help. Also, adding "HELP ME!!!!!!" is a nono. You are not any more important than anyone else. Add to that the ALL CAPS. And for that reason: I'm out.

    @allaudin We don't hand out code solutions here. This is not Rent-A-Coder™. If he passes his school test and becomes a (bad) programmer, I hope he becomes your collegue and he makes you do his work for him.
    Fubarable likes this.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,936
    Rep Power
    4

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    Quote Originally Posted by HelpingIsCaring View Post
    EZ question!!!! help will be EXTREMELY GREATLY appreciated!!!!!!!!!!!!!!!!!
    If you don't know the answer yourself, how do you know its an easy question?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  8. #8
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    Quote Originally Posted by jim829 View Post
    If you don't know the answer yourself, how do you know its an easy question?

    Regards,
    Jim
    oh snap

  9. #9
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    well i just learned a shitton of stuff from this. thank you all! even though most comments are negative lol :)

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,936
    Rep Power
    4

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    Actually, they weren't negative at all. If you hang around the forum enough you will learn that. And more importantly, you will learn a lot about Java.

    Even my comment about your question was based on how you asked it. When you sign up for this forum, I believe it tells you to read the forum rules and guide for posting questions. For some reason (and it's not just you), most folks don't or won't take the time to read them. If they did and followed the guidelines, then these types of comments would be unnecessary.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  11. #11
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    i have read the guide and did the {code} thing. my question is what methods should i use? i realized just asking for the answer isn't helping myself learn :)

  12. #12
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,936
    Rep Power
    4

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    Check the API for the String class. It has a lot of useful methods. Check out StringBuilder too. This and a whole lot of other stuff is covered in the tutorials in my signature link.

    Regards,
    Jim
    HelpingIsCaring likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  13. #13
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Default Re: About strings!!!!!!! HELP ME!!!!!!

    could i use compareTo in this case? im a java noob -_-
    wait no. i dont need to use it.
    Last edited by HelpingIsCaring; 06-28-2013 at 10:10 PM.

  14. #14
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Lightbulb About strings!!!! reposted with update ;)

    i made some changes to the first copy, but still dont really know what to put by the if statement to make everything come together. it would be nice if you could tell me the answer and/or explain it.
    Java Code:
    public class MoreStrings {
    
        public static boolean givenString(String input1, String input2) {
    
    
            char[] words = input1.toCharArray();
    
            boolean result = true;
            char letter = 'g';
            for (int i = 0; i < input1.length(); i++) {
                if (i == letter) {
                    
                   //...... what should i put here?
            }
               
            } return result;
        }
    
           
        
    
        
    
        public static void main(String[] args) {
    
            String input1 = "abcdef ghi jklmn";
            String input2 = "ghi";
            boolean ret = givenString(input1, input2);
            if (ret == true) {
    
                System.out.println(true);
            } else {
    
                System.out.println(false);
            }
    
        }
    }
    Last edited by HelpingIsCaring; 06-28-2013 at 10:38 PM.

  15. #15
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Default Re: About strings!!!! reposted with update ;)

    im a beginner trying to use basic ideas to make things work so i can understand strings better. plz dont reply with different ways of doing this like using substrings or charAt. thanks!!!!

  16. #16
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default Re: About strings!!!! reposted with update ;)

    Again, have a look at String (Java Platform SE 6) since there's a method in there that does exactly what you want.

  17. #17
    Join Date
    Jun 2013
    Posts
    66
    Rep Power
    0

    Default Re: About strings!!!! reposted with update ;)

    the only method that would work would be charAt which i am not suppose to use!

  18. #18
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,936
    Rep Power
    4

    Default Re: About strings!!!! reposted with update ;)

    Clearly, the best way would be to use indexOf(). But apparently you can't do that either. So if you have a string and the only way you can get a character is charAt(),just how do you expect to solve your problem? What methods of the String class are you allowed to use?

    There is absolutely no way I know of to get access to any of the strings characters without using one of the supplied methods.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: About strings!!!! reposted with update ;)

    Two question threads have been merged. Let's try to avoid splitting the discussion into multiple threads.
    DarrylBurke likes this.

  20. #20
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default Re: About strings!!!! reposted with update ;)

    I'm going to assume this is a school assignment, and if there are limitations on what methods you can use, could you post the entire assignment? That way we'd be able to point you in the right direction.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: 03-12-2013, 03:12 PM
  2. Update Function won't update!
    By Indigrace in forum New To Java
    Replies: 3
    Last Post: 02-05-2013, 01:49 PM
  3. Need help with strings please!!!!
    By ndsmith20 in forum New To Java
    Replies: 4
    Last Post: 10-24-2012, 11:24 PM
  4. Strings
    By leepikamukharji in forum New To Java
    Replies: 12
    Last Post: 04-18-2011, 01:43 PM
  5. How to update my jdk???
    By low224 in forum New To Java
    Replies: 4
    Last Post: 01-04-2009, 04:51 PM

Tags for this Thread

Posting Permissions

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