Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Tolls

Thread: count every 45 records and prfix the count number

  1. #1
    dkr786 is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default count every 45 records and prfix the count number

    Hi,

    I have 5000 records in a database, I would like to loop through them and every 45 records I have to append a prefix .

    so first 45 records I append prefix as 1, second 45 records I append prefix as 2 , like that end of 5000 records.

    Please can you help me how to code this requirement in Java.

    Thanks

    Raj.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: count every 45 records and prfix the count number

    Quote Originally Posted by dkr786 View Post
    I have 5000 records in a database, I would like to loop through them and every 45 records I have to append a prefix .

    so first 45 records I append prefix as 1, second 45 records I append prefix as 2 , like that end of 5000 records.

    Please can you help me how to code this requirement in Java.
    What do you have so far, and where are you stuck?

  3. #3
    dkr786 is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: count every 45 records and prfix the count number

    I have some thing like this, but not getting thought how to implement complete logic:

    int count=0;
    for (int i=0;, i<args.length; i++) {
    count+=args[i];
    }
    System.out.println("The total of arguments is: " + count);

    if (count <= 46){
    System.out.println(????)
    }

    Thanks

    Raj

  4. #4
    dkr786 is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: count every 45 records and prfix the count number

    Quote Originally Posted by Fubarable View Post
    What do you have so far, and where are you stuck?
    int count=0;
    for (int i=0;, i<args.length; i++) {
    count+=args[i];
    }
    System.out.println("The total of arguments is: " + count);

    if (count <= 46){
    System.out.println()
    }

    I got up to here so far, need some help on how to build the rest of the logic...thanks in advance.

    Thanks
    Raj

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: count every 45 records and prfix the count number

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    dkr786 is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: count every 45 records and prfix the count number

    Hi Friends,

    Any update ? Please could you give me some guidance...

    Thanks
    Raj

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: count every 45 records and prfix the count number

    You have been.
    Darryl has posted the guide, which includes things like posting code inside [code] tags [/code], and giving us code along with errors/exceptions.
    harshit shah likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    dkr786 is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: count every 45 records and prfix the count number

    Hi , the below is the code I have and got stuck need some input here:

    Java Code:
    		public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		int[] anArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int toCheck = 3;
            int counter =0;
            
    		for (int i=0; i<anArray.length; i++) {
    		
    			if (i == 3) {counter++;}
    			System.out.println("Value: " + anArray[i] +"-"+ counter );
    		}
    		
    	}
    }
    When i run the above code , I am getting the output as :
    Value: 7-1
    Value: 8-1
    Value: 9-1
    Value: 10-1

    But I need as below

    1-1
    2-1
    3-1
    4-2
    5-2
    6-2
    7-3
    8-3
    9-3
    10-4

    Thanks
    Raj
    Last edited by dkr786; 02-15-2013 at 05:55 PM.

  9. #9
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: count every 45 records and prfix the count number

    The reason this isn't working is because of your if statement
    Java Code:
    if (i == 3) {counter++;}
    You would have to use a module(%) to get the correct results
    Java Code:
    if (i%3 == 0) {counter++;}
    You would have to edit the module i provided above to get the exact output you would want.

Similar Threads

  1. Replies: 13
    Last Post: 10-16-2012, 10:47 PM
  2. Count number of rows
    By Kenan_89 in forum Advanced Java
    Replies: 11
    Last Post: 01-26-2012, 12:52 PM
  3. Replies: 8
    Last Post: 01-21-2012, 01:14 AM
  4. How to count records WITHOUT an array?
    By teekei in forum New To Java
    Replies: 17
    Last Post: 07-25-2011, 12:42 PM
  5. day number count
    By droidus in forum New To Java
    Replies: 14
    Last Post: 03-23-2011, 10:15 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
  •