gpt4 book ai didi

java - 你能把变量写进去吗?详情请见

转载 作者:行者123 更新时间:2023-11-29 07:51:38 26 4
gpt4 key购买 nike

有没有一种方法可以简化这段代码,比如先写一个变量,然后再写一遍?我的意思是全部在一条线上。

class tests {
public static void main(String args[]) {
int david, mark, alex;
david = 20;
mark = 30;
alex = 12;

System.out.println("hey");
System.out.print("I can't believe that mark is ");
System.out.print(mark);
System.out.print(" years old.. thank god alex and david are ");
System.out.print(alex);
System.out.print(" and ");
System.out.print(david);
System.out.print("...");
}

}

注意写这么简单的东西需要多少 System.out.print 吗?无论如何仍然使用这些变量来简化这口井?

最佳答案

你总是可以这样做:

System.out.println("hey\n I can't believe that mark is "+mark+" years old.. thank god alex and david are  "+alex+" and "+david+"...");

注意:由于您正在为"hey" 使用println(表示换行),因此您需要添加\n 那里

关于java - 你能把变量写进去吗?详情请见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20696756/

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