Answer to Question #12712 in Java | JSP | JSF for Amy

Question #12712
I want to print out two arrays next to each other horizontally, but can only seem to print them one after the other...

System.out.println ( "Customer ID, Transaction Value " );

for (int i = 0; i < customerID.length; i++) {
System.out.println(customerID[i]);
}


for (int i = 0; i < transactionValue.length; i++) {
System.out.println(transactionValue[i]);

I would like them to be like this.

Customer ID, Transaction Value
1, 33.33
2, 44.44
...

Any ideas?
1
Expert's answer
2012-08-09T08:44:02-0400
System.out.println ( "Customer ID, Transaction Value " );
if
(customerID.length==transactionValue.length){
for (int i = 0; i <
customerID.length; i++) {
System.out.print(customerID[i]+"
");
System.out.println(transactionValue[i]);
}
} else
{System.out.println("Lengths of arrays don't match!");}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS