小编Dav*_*ave的帖子

返回语句打印的值

我想将所有信息作为for语句打印的输出返回.

例如:

public static int countNumbers(int x) {

    for (int i = 1; i <= x; i++) {
        System.out.println(i);
    }

    return SOMETHING; // This something should be the values for statements prints.
                      // For example, countNumbers(5) returns 12345.
}
Run Code Online (Sandbox Code Playgroud)

因此,当我在其他地方调用该方法时,我将得到输出.

所以:

int output = countNumbers(3);
//output = 123;
Run Code Online (Sandbox Code Playgroud)

如何才能做到这一点?

java

0
推荐指数
1
解决办法
65
查看次数

标签 统计

java ×1