 |
do something every 1000 records or so
Ok, this could be a perfect exam question, but it isn't and i need a good solution in a function i get 2 int parameters : begin end they represent the number of records affected , I have to print to a log at the start of this and then every 1000 records or so, the code looks something like this: public Vector findRecords(int beginRange, int endRange) throws UierException { if beginRange == 0 || "some condition so it prints every 1000 records" { logIt(" Range affected" + beginRange + " to " + endRange); ..... I would really appreciate the help oh and by the way, the range varies, it could be 20, 40, 120, or whatever, so the condition has to check that between beginRange and endRange is more that 1000x i m not sure I m explaining the problem properly, so if its not clear please ask. also there might be an incredibly easy solution, but i just cant see it :( Thanks in advance for the help jo
Jo wrote: > Ok, this could be a perfect exam question, but it isn't and i need a > good solution
I'll believe you. > if beginRange == 0 || "some condition so it prints every 1000 records" {
I think you need the modulo (%) operator. This gives the remainder of an integer division, which will, of course be zero every n records when you modulo by n. For example 25 % 25 == 0, 50 % 25 == 0, 51 % 25 == 1 and so on. -- Regards, Richard
On May 15, 10:36 am, Richard Senior <nos@r-senior.demon.co.uk> wrote:
> Jo wrote: > > Ok, this could be a perfect exam question, but it isn't and i need a > > good solution > I'll believe you. > > if beginRange == 0 || "some condition so it prints every 1000 records" { > I think you need the modulo (%) operator. This gives the remainder of an > integer division, which will, of course be zero every n records when you > modulo by n. For example 25 % 25 == 0, 50 % 25 == 0, 51 % 25 == 1 and so on. > -- > Regards, > Richard
hi there: the problem is that i dont have an exact brake, ie if i do a module on 1050 i ll get 1, and some mod but what happens when i get 1090? i ll get 1 again, so how do i make it print only the first time ?
Jo wrote: > the problem is that i dont have an exact brake, ie if i do a module on > 1050 i ll get 1, and some mod > but what happens when i get 1090? i ll get 1 again, so how do i make > it print only the first time ?
I don't understand. Isn't this essentially what you want? public class Modulo { private static final int START = 1; private static final int FINISH = 50; private static final int INTERVAL = 5; public static void main(String[] args) { for (int i = START; i <= FINISH; i++) { if (i == START || i % INTERVAL == 0) { System.out.print(i); } else { System.out.print("."); } } } }
-- Regards, Richard
Thanks for your reply but no, have a look at the original code on the fucntion, that function is called for example with parameters findRecords(0,39) findRecords(40,120) findRecords(121,200) .... or findRecords(0, 60) findRecords(61, 120) findRecords(121, 180) ... what i need to implement is that if between beginRange and endRange there is a 000 number then i run the line logIt(" Range affected" + beginRange + " to " + endRange); Where logit is a custom function that writes to a log in my app. I hope is a bit more clear now Thanks jo On May 15, 2:33 pm, Richard Senior <nos@r-senior.demon.co.uk> wrote:
> Jo wrote: > > the problem is that i dont have an exact brake, ie if i do a module on > > 1050 i ll get 1, and some mod > > but what happens when i get 1090? i ll get 1 again, so how do i make > > it print only the first time ? > I don't understand. > Isn't this essentially what you want? > public class Modulo { > private static final int START = 1; > private static final int FINISH = 50; > private static final int INTERVAL = 5; > public static void main(String[] args) { > for (int i = START; i <= FINISH; i++) { > if (i == START || i % INTERVAL == 0) { > System.out.print(i); > } > else { > System.out.print("."); > } > } > } > } > -- > Regards, > Richard
|
 |