Results 1 to 4 of 4
  1. #1
    iPetey is offline Member
    Join Date
    Apr 2009
    Posts
    11
    Rep Power
    0

    Cool help error in while loop

    i'm working on an assignment for one of my computer classes and this line of code seems to give me the error ')' expected. i am super new to java and i am using blue J. if someone could please tell me why i am having this problem or what i'm doing wrong. i'm making a shoppingcart with 2 classes.
    public void findItem(String searchName){

    int index=0;
    boolean found = false;

    while((index<cart.size())if!found){

    StoreItem.item = cart.get(index);
    String itemName=item.getName();
    if(itemName.contains(searchName){
    system.out.print("Item Found :")
    system.out.print(item.toString();
    found = true;
    }
    else
    index++;
    }

    if(!found){
    system.out.print("notfounddawgggy")
    }

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

    Default

    This doesn't make sense I'm afraid:
    Java Code:
    while((index<cart.size())if!found){
    what are you trying to do here exactly?

    Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    oh, and welcome to the forum!

  3. #3
    iPetey is offline Member
    Join Date
    Apr 2009
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    This doesn't make sense I'm afraid:
    Java Code:
    while((index<cart.size())if!found){
    what are you trying to do here exactly?

    Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag
    Java Code:
     above your pasted code and the tag
    below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]

    oh, and welcome to the forum!
    i am trying to search thru an arraylist but also trying to make sure the loop doesn't keep continuing on. i'm making a shoppingcart, this damn assignment has me stressed out!
    sorry i didn't know the proper way to state the code, will do next time.

    thanks for the welcome =]

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

    Default

    Are you trying to do this?
    Java Code:
    while((index<cart.size()) && !found){
    sorry i didn't know the proper way to state the code, will do next time.
    No need to apologize.

    and good luck.

Similar Threads

  1. Loop Help
    By HeavyD in forum New To Java
    Replies: 7
    Last Post: 09-22-2010, 09:55 PM
  2. Replies: 3
    Last Post: 01-23-2009, 08:53 AM
  3. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 04:28 PM
  4. can you help me with this for loop?
    By java_fun2007 in forum New To Java
    Replies: 6
    Last Post: 12-22-2007, 10:20 AM
  5. While loop
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 03:11 PM

Posting Permissions

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