gpt4 book ai didi

java - 如何通过 OOP 打印多个值而不用在 Java 中添加它们

转载 作者:行者123 更新时间:2023-12-02 11:35:14 24 4
gpt4 key购买 nike

我想要的是打印出这些方法中的每一个,而不是将它们的值加在一起。我认为这就是为什么我在尝试将 boolean 值放入第一个 System.out 语句中时出错的原因。我是否必须为每个人提供自己的 System.out.println 语句?

public class Main {
public static void main(String[] args)
{
Block dirt = new Block(1, 100, 1, false, false, 0, 1, 100, 1)
{

};
System.out.println(dirt.getSpawnLevel() + dirt.getSize() + dirt.getHardness() + dirt.getOpacity() + dirt.getRarity() + dirt.getBounceHeight() + dirt.getStackSize());

System.out.println(dirt.getFlammable());
System.out.println(dirt.getBlockBounce());

}

}

最佳答案

Block dirt = new Block(1, 100, 1, false, false, 0, 1, 100, 1)
{

};

将之前的代码更改为:

Block dirt = new Block(1, 100, 1, false, false, 0, 1, 100, 1);

还可以像这样打印输出:

System.out.println(dirt.getSpawnLevel()+"," + dirt.getSize()+"," + dirt.getHardness()+"," + dirt.getOpacity()+"," + dirt.getRarity()+"," + dirt.getBounceHeight()+"," + dirt.getStackSize());

关于java - 如何通过 OOP 打印多个值而不用在 Java 中添加它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48991851/

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