gpt4 book ai didi

java - 生成 "_ _ _ "的方法仅返回 "_ "

转载 作者:行者123 更新时间:2023-12-02 05:33:08 28 4
gpt4 key购买 nike

我的方法有问题。我需要从主类调用的方法的输出打印我:

需要这个输出:_ _ _ _ _

我知道我可以将 System 的静态方法放入循环中,但这不是我想要的解决方案。我需要它来打印主类中方法的输出。

    // This is my method which I made in my class

public String wordRows(int count){

// inicializace proměnné v charu
String r = "_";
String space = " ";
String spaceR = "";
for( int i = 0; i <= count; i++){
//System.out.print(r + space);
spaceR = r + space;
}

return spaceR;

}

// Declaration of method in main class

public class TestedProjectOfGuessword {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Rows rows = new Rows();

System.out.println(rows.wordRows(8))

最佳答案

您需要附加到 spaceR

spaceR = spaceR + r + space;

关于java - 生成 "_ _ _ "的方法仅返回 "_ ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25316647/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com