我怎么能用一个逗号分隔一行? [英] How could I have my output separated in a line by exactly one comma?
本文介绍了我怎么能用一个逗号分隔一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的输出形式为1 1 1 2 2,但我想打印一行中用一个逗号分隔的数字
我尝试过:
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);
}
}
推荐答案
开始使用:
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.
你有一个 String [] 作为输入,为什么不用 String.join 作为输出?
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);
}
这篇关于我怎么能用一个逗号分隔一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文