Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

I need to write a code that recieve an integer and find whether it forms an ascending series or not.
for example:
123 - true
2579 - true
321 - false
1338 - false
222 - false
5 - true

I wrote this recursion but i don't get the right result
can someone tell me what's wrong with it please?
Thanks...

```private static boolean numCheck(int num) {

if ((num/10) == 0) {
return true;
} else {
if ((num % 10) > ((num/10) % 10)) {
numCheck(num/10);
} else {
return false;
}
}

}```

2. ## The Following User Says Thank You to nil For This Useful Post:

javapenguin (October 18th, 2010)

What result do you get instead? What should the algorithm do?

Post an SSCCE that demonstrates the problem, and we'll go from there.

Originally Posted by nil
I need to write a code that recieve an integer and find whether it forms an ascending series or not.
for example:
123 - true
2579 - true
321 - false
1338 - false
222 - false
5 - true

I wrote this recursion but i don't get the right result
can someone tell me what's wrong with it please?
Thanks...

private static boolean numCheck(int num) {

if ((num/10) == 0) {
return true;
} else {
if ((num % 10) > ((num/10) % 10)) {
numCheck(num/10);
} else {
return false;
}
}

}
I can't see anything wrong, unless you're entering negative values.

123%10 = 3

123/10 = 12;

12%10 = 2;

3 > 2;

numCheck(12);

12%10 = 2;

12/10 = 1;

1%10 = 1;

2 > 1;

numCheck(1);

1/10 = 0;

return true;

122%10 = 2;

122/10 = 12;

12%10 = 2;

2 = 2;

return false;