Heres the senario I have alot of Int values that I read from a file, for example: 0,63,12,45,23,56,67,32,56,9,3,0,34 what i need to do is setup a statement where if its less than 10 it will add 1 to a Int called markZero it needs to go round in a big loop and do it till its gone through all the characters. this is what ive got so far i think its correct but im not sure about the loop its the only thing thats getting it wrong.
OK, this looks like a reasonable start. You are missing a few ingredients, though! The loop should iterate through each of the marks. But at the moment, the value of submark never changes within the body of the loop. That means that your loop will never end because submark will never be 98 (unless it started that way). It's not clear from your code where those marks are being stored. Are they stored in a comma-separated string, or have you already processed the marks and added them to an array or a List? Assuming that the marks are stored in an array:
The following code would iterate through the marks and increment the markZero variable:
I've used a for loop rather than a do..while because it is more usual for this kind of iteration. It is also better for the loop condition to be checked at the start rather than at the end, so that it won't try to access the array if it is empty (that would cause a RuntimeException). This is the equivalent code with a while loop.
[ May 09, 2004: Message edited by: David Peterson ]
Joined: Apr 21, 2004
ok thats very helpful, I'll go into alittle more detail i have a file which contains numbers i read them and then they go into a int file. what i need to do is to setup a statement that reads the file and then counts down it and splits it into groups. Im not sure if the Int is an array though i need to know if that makes a different or not? the Int file is called submark and i know it contains the numbers because when i outprint it comes up with all the numbers. What i really need is to get the loop working for 0 <10 once ive got that i can do the rest of them. Any help would be so so so so greatly approved its really this is getting me very stressed. You can see from my original code what i have so far the while i think means to go through 89 becuase there are 89 numbers in the file