Array for loop

The code below finds the correct information from the array "info", only thing is it displays it in a series of message dialogs as the for loop executes. I want to display the details in one dialog. Can anyone advise how to collate the details during the for loop and display as one string output after the loop ends. Some code would be helpful.

Thanks

switch (option2)
{

//user selects cycle option
case 1: for (int row = 0; row < info.length; row ++)
{
if(info[row][5].equalsIgnoreCase("Yes"))

JOptionPane.showMessageDialog(null,"Customers who use the cycle are" + '
'
+ (info[row][0] + " " + info[row][1]));

}

break;

Comments

  • [blue]If you use the c++ string class it will be pretty trivel. Just concantinate the strings until the loop is finished.[/blue]
    [code]
    [red]#include
    using namespace std;[/red]
    :
    : switch (option2)
    : {
    [red]string msg;[/red]
    : //user selects cycle option
    : case 1: for (int row = 0; row < info.length; row ++)
    : {
    : if(info[row][5].equalsIgnoreCase("Yes"))
    :
    [red]msg += info[row][0] + " " + info[row][1] + "
    ";[/red]
    :
    : }
    [red]JOptionPane.showMessageDialog(null,msg.c_str());[/red]
    : break;
    :
    :
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion