in the below text sum the amount to those FLAG & MA_NAME fields are same and put them in one array, and unique item append to that array i did some work but difficult to get unique items


FLAG MA_NAME SUM_AMT
-------- ---------------------------------------- ----------
Credit CASH 7777
Credit Salaries 9999
Credit Salaries Payable 2222
Credit Salaries Payable 5000
Credit State Bank of India 22
Credit State Bank of India 3000
Credit Sundry Debtors 2001
Credit Sundry Debtors 6666
Debit CASH 4444
Debit CASH 4999
Debit Salaries 3333
Debit Salaries 5678
Debit Salaries Payable 22
Debit Salaries Payable 4567
Debit State Bank of India 3333
Debit Sundry Debtors 3456

in tha below code iam getting duplicate variables, how to get unique items
for(i=0;i<p;i++)
 {
	 String x=MANAME[i];
	 String y=FLAG[i];
	 int z=AMT[i];
	 for(j=i+1;j<p-1;j++)
	 {
		 String x1=MANAME[j];
		 String y1=FLAG[j];
		 int z1=AMT[j];
		 if((x.equals(x1)) && (y.equals(y1)))
		 {
			 NAME[l]=x;
			 CRDR[l]=y;
			 SUM[l]=z+z1;
			 l++;
		 }//if
		
	 }//for(j
 }//for(i

Recommended Answers

All 5 Replies

in the below text sum the amount to those FLAG & MA_NAME fields are same and put them in one array, and unique item append to that array i did some work but difficult to get unique items

[TEX]
FLAG     MA_NAME                                     SUM_AMT
-------- ---------------------------------------- ----------
Credit   CASH                                           7777
Credit   Salaries                                       9999
Credit   Salaries Payable                               2222
Credit   Salaries Payable                               5000
Credit   State Bank of India                              22
Credit   State Bank of India                            3000
Credit   Sundry Debtors                                 2001
Credit   Sundry Debtors                                 6666
Debit    CASH                                           4444
Debit    CASH                                           4999
Debit    Salaries                                       3333
Debit    Salaries                                       5678
Debit    Salaries Payable                                 22
Debit    Salaries Payable                               4567
Debit    State Bank of India                            3333
Debit    Sundry Debtors                                 3456
in tha below code iam getting duplicate variables, how to get unique items
for(i=0;i<p;i++)
 {
	 String x=MANAME[i];
	 String y=FLAG[i];
	 int z=AMT[i];
	 for(j=i+1;j<p-1;j++)
	 {
		 String x1=MANAME[j];
		 String y1=FLAG[j];
		 int z1=AMT[j];
		 if((x.equals(x1)) && (y.equals(y1)))
		 {
			 NAME[l]=x;
			 CRDR[l]=y;
			 SUM[l]=z+z1;
			 l++;
		 }//if
		
	 }//for(j
 }//for(i

now analyse what you wrote and translate it into correct English.
When you've done that come back and try again. What you wrote there is impossible to comprehend.

In the above i provide 3 fields with data, in that i have to get the data as
uniquely means
which are duplicate fields (flag & ma_name) aggregate as one record by sum their amt.
which are unique display as it is.

@brr

Do not flood the forum by posting the same question more than once

and it still needs to learn to write proper English...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.