# Arrays

• 04-18-2010, 07:18 PM
PhQ
Arrays
For example, my XP is 878,
and I have:
Code:

`int levelxp[]={0, 0, 21, 78, 57, 248, 486, 1084, 2147};`
My level should be 8 because it is between 486 and 1084. How can I print this out?
• 04-18-2010, 07:49 PM
JosAH
Quote:

Originally Posted by PhQ
For example, my XP is 878,
and I have:
Code:

`int levelxp[]={0, 0, 21, 78, 57, 248, 486, 1084, 2147};`
My level should be 8 because it is between 486 and 1084. How can I print this out?

Check for a value i w.r.t. levelxp[i] <= XP <= levelxp[i+1]

kind regards,

Jos
• 04-18-2010, 08:06 PM
Cruncher
Code:

```        int exp = 878;         int levelxp[] = {0, 0, 21, 78, 57, 248, 486, 1084, 2147};         int level = 0;         for (int i = 0 ; i < levelxp.length ; i++)         {             if (levelxp [i] > exp)             {                 level = i;                 break;             }         }         System.out.println (level);```
something like this should work

edit: Oh, are they not in order?
• 04-18-2010, 08:40 PM
PhQ
Quote:

Originally Posted by Cruncher
Code:

```        int exp = 878;         int levelxp[] = {0, 0, 21, 78, 57, 248, 486, 1084, 2147};         int level = 0;         for (int i = 0 ; i < levelxp.length ; i++)         {             if (levelxp [i] > exp)             {                 level = i;                 break;             }         }         System.out.println (level);```
something like this should work

edit: Oh, are they not in order?

Thanks, that's what I was looking for.