Results 1 to 4 of 4
Thread: Need help with a loop
- 11-22-2010, 11:38 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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. :)
- 11-22-2010, 11:45 PM #2
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?
- 11-23-2010, 09:53 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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.
- 11-23-2010, 10:08 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Help with Loop
By PsychoNaut in forum New To JavaReplies: 2Last Post: 10-14-2010, 06:01 AM -
While loop for jpg
By TheBigB in forum New To JavaReplies: 1Last Post: 07-29-2010, 08:25 PM -
How can I rewrite the following while loop using a for loop?
By gt11990 in forum New To JavaReplies: 5Last Post: 04-30-2010, 05:05 PM -
Which loop to use?
By meee in forum New To JavaReplies: 1Last Post: 09-07-2009, 09:36 AM -
while-loop stopping on first loop
By davester in forum New To JavaReplies: 6Last Post: 06-26-2009, 08:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks