Question: I have tried the other questions like this but none seem to match it. I want it to repeat if the user enters Y after the numbers are sorted in the console.
Here is the code:

```
package compsorter;
import java.util.Scanner;
public class Ascending_Order 
{
    public static void main(String[] args) 
    {
    int n, temp;
    Scanner s = new Scanner(System.in);
    System.out.print("Enter no. of elements you want in array:");
    n = s.nextInt();
    int a[] = new int[n];
    System.out.println("Enter all the elements:");

    for (int i = 0; i < n; i++) 
    {
        a[i] = s.nextInt();
    }
    for (int i = 0; i < n; i++) 
    {
        for (int j = i + 1; j < n; j++) 
        {
            if (a[i] > a[j]) 
            {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    System.out.print("In Ascending Order:");
    for (int i = 0; i < n - 1; i++) 
    {
        System.out.print(a[i] + ",");
    }
    System.out.print(a[n - 1]);
    s.close();
}
}

```

Thanks!

Answer: 
The only problem with the recursive solution is the stack over flow problem. A way to do it without recursion is

```
Observable<ArtistsCursorPager> allPages = Observable.defer(() ->
{
    BehaviorSubject<Object> pagecontrol = BehaviorSubject.create("start");
    Observable<ArtistsCursorPager> ret = pageControl.asObservable().concatMap(aKey ->
    {
        if (aKey != null && aKey.equals("start")) {
            return Observable.getFollowedArtists(50).doOnNext(page -> pagecontrol.onNext(page.cursors.after));
        } else if (aKey != null && !aKey.equals("")) {
            return Observable.getFollowedArtists(50,aKey).doOnNext(page -> pagecontrol.onNext(page.cursors.after));
        } else {
            return Observable.<ArtistsCursorPager>empty().doOnCompleted(()->pagecontrol.onCompleted());
        }        
    });
    return ret;
});

```

See the solutions to [this question](https://stackoverflow.com/questions/37326380/paginate-observable-results-without-recursion-rxjava).
Thanks for opening my eyes that I didn't read your question properly. Here is the best solution i can suggest you without using the normal recursive function but the RxJava way. 

```
PublishSubject<Integer> limit = PublishSubject.create();

        limit.concatMap(integer -> Observable.just(integer + 1)) // Assuming this gives network result based upon the artist id you provided
                .doOnNext(integer -> {
                    // Based on the network result i make my conditions here. Pass the 50th artist id here. otherwise call onCompleted.
                    Timber.d("Publish: doOnNext: %d", integer);
                    if (integer < 10) {
                        // Pass the artist id to make the next call
                        limit.onNext(integer);
                    } else {
                        limit.onCompleted();
                    }
                })
                .toList()
                .subscribe(integers -> Timber.d("Publish: All the results"));

        limit.onNext(1); // For demo, I'm starting here with 1. You have to pass the artist id here

```

The output looks like following:

```
Publish: doOnNext: 2       
Publish: doOnNext: 3       
Publish: doOnNext: 4       
Publish: doOnNext: 5       
Publish: doOnNext: 6       
Publish: doOnNext: 7       
Publish: doOnNext: 8       
Publish: doOnNext: 9       
Publish: doOnNext: 10      
Publish: All the results

```

The `toList()` operator gives you list of all the responses you've got in the end when all the calls have been made. Have a look at `reduce()` operator as well.