English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i've randomed arrays i.e.
for(x=0;x<6;x++)
thing[x]=rand%50+1;
and then the user will input some data. How will i compare the arrays to the data (the data are also arrays)

2007-01-18 20:27:10 · 1 answers · asked by Sammy Baby 1 in Computers & Internet Programming & Design

i want to compare every randomed variable to the data input by the user (both are arrays), i want to compare random[0] with input[0], input[1] etc... random[1] with input[0], input[1] etc... how will i do that?

2007-01-18 20:58:50 · update #1

1 answers

for (int i=0; i < data.length; i++)
{
for (int y =0 ; y < thing.length; i++)
{
if (thingx[y] > data[i]) //use >. <. == depending on what comparison you want to perform
//do something
}
}

Just saw your additional information...
I am assuming that both arrays are of the same length. There are many ways to do the comparison

this is one...
for (int i =0; i< random.length; i++)
{
if (random[i] < input[i])
//do something
}

If the length of the arrays is not necessarily the same then do this
int length = 0;
if (random.length >= input.length) //if random length is greater or equals to input length, set the length to the min length
length = input.length;
else
{
length = random.length;
}
for (int i=0; i < length; i++)
{
if (random[i] < input[i])
//do something
}

2007-01-18 20:35:52 · answer #1 · answered by Anonymous · 0 0

fedest.com, questions and answers