Recursive numeric sequence in Java

0

I need to make a numerical sequence in recursive mode that, after reaching n number (5, in the example), starts to do the inverse sequence.

Example:

  

1234554321

I've already done what the normal sequence does, now there's one that reverses the numbers. Can you help me?

import java.util.Scanner;

public class Main
{
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        System.out.println("Sequencia numerica...\n");
        int sequencia = nSequencia(1);
    }

    static int nSequencia(int iSequencia) {
        System.out.print(iSequencia);
        if(iSequencia >= 5){
            return 1;
        }
        else{
            return nSequencia(iSequencia + 1);
        }
    }  
}
    
asked by anonymous 15.08.2017 / 21:00

0 answers