1. ## Arrays

For example, my XP is 878,
and I have:
Java 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?

2. Originally Posted by PhQ
For example, my XP is 878,
and I have:
Java 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

3. Member
Join Date
Mar 2010
Posts
88
Rep Power
0
Java 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?
Last edited by Cruncher; 04-18-2010 at 08:09 PM.

4. Originally Posted by Cruncher
Java 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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•