Results 1 to 4 of 4
  1. #1
    Goldie26690 is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default Need help with a loop

    Hi guys, I have an array of stock, which has variables - part numbers, stock quantity etc and I am trying to issue stock from the array. I am using a method issueStock(), the method has no parameters. In the method i am asking the user to input the part number of the item they wish to issue in turn i am searching the array comparing the user's inputed data to part numbers in the array. I am having trouble using a for loop when the part number is not found, I am using if statements inside the for loop but with no success.

    Any ideas? I am only new to this and am not sure if the above query is even making sense. Any feedback would be great. :)

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    Posting code can usually help bring sense to posts like this. What is the declaration of your array? What type of objects are in it? What is the class for those objects (if applicable)? What have you tried--and what isn't working about your attempts?

  3. #3
    Goldie26690 is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    Scanner sc = new Scanner(System.in);
    System.out.println("Please enter part code you wish to issue");
    int d = sc.nextInt();
    for(int i = 0; i < stores.length; i++)
    {
    if(d == stores[i].getPartCode())
    {
    System.out.println("Please enter number of stock you wish to issue");
    int n = sc.nextInt();
    }
    else if(d != stores[i].getPartCode())
    {
    System.out.println("Part code entered is wrong");
    }


    When the right part code is entered the for loop does not stop it keeps running for the length of the stores array, I have noticed that by the end of the loop it will always print out "Part code entered is wrong" if I enter the first part code in the array, "Part code entered is wrong" will print out 7 times (there is 8 items in the array). The array is filled already with cleaning, stationary and food items, the user does not enter these into the array.

  4. #4
    Goldie26690 is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    also I have tried a Do - While and a While loop with no luck,

    Thanks Zach for the reply I hope this information will help you help me.

Similar Threads

  1. Help with Loop
    By PsychoNaut in forum New To Java
    Replies: 2
    Last Post: 10-14-2010, 06:01 AM
  2. While loop for jpg
    By TheBigB in forum New To Java
    Replies: 1
    Last Post: 07-29-2010, 08:25 PM
  3. Replies: 5
    Last Post: 04-30-2010, 05:05 PM
  4. Which loop to use?
    By meee in forum New To Java
    Replies: 1
    Last Post: 09-07-2009, 09:36 AM
  5. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 08:46 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
  •