13,701,759 members
See more:
I have a output in form "1 1 1 2 2 " but I wanted to print the numbers separated in a line by exactly one comma

What I have tried:

```<pre lang="java"><pre>public class Main {

static int a = 0;
static int b = 0;

public static void main(String[] args) {

int n = Integer.parseInt(args[0]);
a = Integer.parseInt(args[1]);
b = Integer.parseInt(args[2]);
for (int i = 0; i <= n; i++){
System.out.print(recursiv(i));}

}

public static long recursiv(int n) {

if (n >= 0 && n <= 2)
return 1;

else
return a * recursiv(n - 2) + b * recursiv(n - 3);

}

}```
Posted 16-May-18 6:54am
Updated 16-May-18 9:00am

## Solution 1

Get started with:
```for (int i = 0; i <= n; i++){
System.out.print(recursiv(i));
System.out.print(",");
}
```

I let you handle the last number.
16-May-18 15:18pm

thank you very much , I have solved it with for- loop .
for (int i = 0; i <= n; i++){
System.out.print(recursiv(i));
if(i<n){
System.out.print(",");}
}
Patrice T 16-May-18 15:49pm

Nice to see it

## Solution 2

As you have a String[] as the input, why don't you just use String.join for the output?

```public static void main(String[] args) {
System.out.print(String.join(",", args);
}
```
v2

Top Experts
Last 24hrsThis month
 OriginalGriff 613 KarstenK 116 Richard Deeming 110 CHill60 95 Patrice T 78
 OriginalGriff 5,525 Patrice T 1,659 Richard MacCutchan 1,503 Maciej Los 1,204 Richard Deeming 733