Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI store tha array like this : int val1[] = { 0, 1, 3, 3, 5, 5, 8}; int val2[] = { 0, 6, 4, 3, 2, 7, 5}; And now I want to compare the values in val1 and values in val2, I tried this algorithm but it does not work fine: for(int j = 0; j <= len1; j++) { for(int k = 0; k <= len2; k++) { if(val1[j] >= val1[j+1] && val2[k] >= val2[k+1]) { System.out.println("Value1 = " + val1[j] + " Value2 = " + val2[k]); } } }
      singulars
    2. COWhen you say you are trying to compare val1 to val2 ... Your example code matches every entry in val1 to every entry in val2, i.e. 7 x 7 = 49 matches, but then doesn't compare val1 to val2, but rather compares each val1 entry to the following val1 entry, and each val2 entry to the following val2 entry. And by the way if len1 is the number of entries in val1, this won't work, because you're running j up to len1, but the last entry in val1 is len1-1. Normally a loop through an array should be for (int j=0;j<val1.lenth;++j) -- note "<", not "<=". Also, comparing val1[j] to val1[j+1] means ...
      singulars
    3. CO... that j must stop at the entry before the last, or you'll be trying to compare the last entry to the entry after the last, and of course there is no "entry after the last". But really the issue here is, What do you mean when you say you want to compare val1 to val2? Do you just want to check if val1[0]==val2[0], val1[1]==val2[1], etc? Or is the comparison more complex?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload