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: searching a string

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default searching a string

    so for some reason it doesn't run even though i typed it as the book said to do

    import javax.swing.*;
     
    public class JProject3
    {
        public static void main(String[] args)
        {
    	    int k,m,x;
    	    String Bean;
    /*
            for (k=0; k<20; k++)
            {
                System.out.println("The values are\t" + ((k*2)-11));
    	    }
     
            System.out.println();
            System.out.println();
     
    	    for (k=0; k<20; k++)
    	    {
    			System.out.println("The values are\t\t" + ((k+1)*101));
    	    }
     
            System.out.println();
            System.out.println();
     
    	    m = 1;
    	    for (k=0; k<20; k++)
    	    {
    			if (m==1)
    			{
    				System.out.println("The Values are\t\t\t" + (Math.pow(10,(k+2))));
    		    }
    		    else
    		    {
     
    		        System.out.println("The Values are\t\t\t" + (Math.pow(10,k)));
    		        k=k-1;
    		    }
    		    m=m*(-1);
    		}
     
            System.out.println();
            System.out.println();
     
    		for (k=0; k<20; k++)
    		{
    			System.out.println("The Values are \t\t\t\t" + ((k+1)*(k+1)*(k+1)));
    		}
            System.out.println();
     
            x = 10;
            for (k=0; k<20; k++)
            {
            System.out.println("This works " + Math.round((1/Math.sqrt(5))*((Math.pow(((1+Math.sqrt(5))/2),k))-(Math.pow(((1-Math.sqrt(5))/2),k)))));
    	    }
    	    */
     
    	    Bean = JOptionPane.showInputDialog("Give me an input");
    	    if ( (searchStr(Bean,f)) == f)
    	    {
    			System.out.println("AWESOME");
    		}
    		else
    		{
    			System.out.println("Not Awesome");
    		}
     
        }
    }

    its at the very end of the code where im trying to search an input for f that im running into a problem with.


  2. #2
    Member wolfgar's Avatar
    Join Date
    Oct 2009
    Location
    the middle of the woods
    Posts
    89
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: searching a string

    i'm betting theirs another function that u missed some where
    some times they leave pieces out so u have to read through and find
    the part that needs added

    also u did a LOT of useless typing
    the first part has no use at all , everything from "/*" to "* /" XD

    from the looks of the method call u need something like this
    public static string searchStr(String input,String search){
       if (input.contains(search)){
          return search;
       } else {
          return null;
       }
    }
    Programming: the art that fights back

Similar Threads

  1. How to return sub string from String
    By humdinger in forum Collections and Generics
    Replies: 1
    Last Post: February 14th, 2010, 11:16 AM
  2. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  3. Having trouble insert/sorting array values w/ binary searching.
    By bh-chobo in forum Collections and Generics
    Replies: 4
    Last Post: October 8th, 2009, 02:38 AM
  4. Searching Data
    By kalees in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: October 2nd, 2009, 03:23 AM
  5. Spanish Java programmers
    By koko10ar in forum Project Collaboration
    Replies: 0
    Last Post: November 15th, 2008, 12:31 PM