Results 1 to 9 of 9
- 02-14-2013, 10:32 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
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.
-
Re: count every 45 records and prfix the count number
- 02-14-2013, 11:02 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
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
- 02-15-2013, 01:02 AM #4
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Re: count every 45 records and prfix the count number
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
- 02-15-2013, 05:05 AM #5
Re: count every 45 records and prfix the count number
Why do they call it rush hour when nothing moves? - Robin Williams
- 02-15-2013, 03:07 PM #6
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Re: count every 45 records and prfix the count number
Hi Friends,
Any update ? Please could you give me some guidance...
Thanks
Raj
- 02-15-2013, 03:35 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.Please do not ask for code as refusal often offends.
- 02-15-2013, 05:08 PM #8
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
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:
When i run the above code , I am getting the output as :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 ); } } }
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
RajLast edited by dkr786; 02-15-2013 at 05:55 PM.
- 02-15-2013, 07:31 PM #9
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
Re: count every 45 records and prfix the count number
The reason this isn't working is because of your if statement
You would have to use a module(%) to get the correct resultsJava Code:if (i == 3) {counter++;}
You would have to edit the module i provided above to get the exact output you would want.Java Code:if (i%3 == 0) {counter++;}
Similar Threads
-
How to count the total records for each unique first 2 characters in an Input File .
By renu in forum New To JavaReplies: 13Last Post: 10-16-2012, 10:47 PM -
Count number of rows
By Kenan_89 in forum Advanced JavaReplies: 11Last Post: 01-26-2012, 12:52 PM -
Easy Question! Print out file, count number of lines, number of spaces w/ Scanner
By LogicalOutlier in forum New To JavaReplies: 8Last Post: 01-21-2012, 01:14 AM -
How to count records WITHOUT an array?
By teekei in forum New To JavaReplies: 17Last Post: 07-25-2011, 12:42 PM -
day number count
By droidus in forum New To JavaReplies: 14Last Post: 03-23-2011, 10:15 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks