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: hello... i am a beginner...

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

    Default hello... i am a beginner...

    Item[]items = new Item[4];
    items[0]= new Item("n",2.2,4);
    items[0].setName("OJ");
    items[0].setCost(6.00);
    items[0].setQty(10);

    items[1]= new Item("n",2.2,4);
    items[1].setName("Milk");
    items[1].setCost(3.99);
    items[1].setQty(20);

    items[2]= new Item("n",2.2,4);
    items[2].setName("Snicker");
    items[2].setCost(0.79);
    items[2].setQty(75);

    items[3]= new Item("n",2.2,4);
    items[3].setName("Wheat Bread");
    items[3].setCost(2.49);
    items[3].setQty(5);


    items[0].getName();
    items[0].getCost();
    items[0].getQty();


    items[1].getCost();
    items[1].getName();
    items[1].getQty();

    items[2].getName();
    items[2].getCost();
    items[2].getQty();

    items[3].getName();
    items[3].getCost();
    items[3].getQty();

    Scanner scan = new Scanner(System.in);
    String input = scan.next();
    for(int i=0; i<items.length; i++)
    {
    if(input.equals(items[i].getName()))
    {
    System.out.println("Item Found");
    }

    else
    {
    System.out.println("Item Not Found");
    }

    }

    The output is
    Item Not Found
    Item Found
    Item Not Found
    Item Not Found

    It is comparing every ite
    m in the array and printing the message. How can only have it print Item Found with out the other message. Please help me with this.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: hello... i am a beginner...

    Please post your code in the section for asking questions. This section is for member introductions.

    Be sure to wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    You need to post a complete program and the full contents of the command prompt window that shows what the program printed and what the user entered.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Beginner
    By mkarthik90 in forum Member Introductions
    Replies: 1
    Last Post: February 18th, 2012, 02:26 PM
  2. I am a beginner please help :)
    By mvonb17 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 6th, 2012, 03:44 PM
  3. Beginner
    By codejava in forum Member Introductions
    Replies: 2
    Last Post: August 22nd, 2011, 08:11 AM
  4. Beginner
    By angelo24 in forum Member Introductions
    Replies: 1
    Last Post: August 19th, 2011, 07:14 AM
  5. I need a help ! i am beginner
    By yinky in forum Java Theory & Questions
    Replies: 3
    Last Post: September 30th, 2009, 07:22 AM