Java,包括打印行中的int变量 你如何在这个句子的中间插入一个变量 System.out.println("Since there are (trying to insert int bluerocks here) there must be less than 12 normal rocks "+bluerocks);
您可以通过几种方式实现这一点,Java支持内联字符串连接,因此这是有效的:Java,包括打印行中的int变量 你如何在这个句子的中间插入一个变量 System.out.println("Since there are (trying to insert int bluerocks here) there must be less than 12 normal rocks "+bluerocks);,java,Java,您可以通过几种方式实现这一点,Java支持内联字符串连接,因此这是有效的: System.out.println("Since there are " + bluerocks + " there must be less than 12 normal rocks "); 或者,您可以使用格式化方法: 你可以像这样使用 或者,像 你有一些选择 或者使用字符串连接,就在您想要的位置,注意引号的数量: System.out.println("Since there are (" + blueroc
System.out.println("Since there are " + bluerocks + " there must be less than 12 normal rocks ");
或者,您可以使用格式化方法:
你可以像这样使用
或者,像
你有一些选择 或者使用字符串连接,就在您想要的位置,注意引号的数量:
System.out.println("Since there are (" + bluerocks
+ ") there must be less than 12 normal rocks");
…或通过printf替换符号:
这里的许多人都给了你正确的答案
System.out.println("Since there are " + bluerocks + " there must be less than 12 normal rocks");
或
或
但是,如果这看起来很复杂或困难,那么你可以将其分解为多个打印语句
System.out.print("Since there are ");
System.out.print(bluerocks);
System.out.print(" there must be less than 12 normal rocks\n");
这都是关于学习的,不需要在这里大惊小怪。System.out.println因为有+蓝岩+必须少于12个普通岩;或者看String.formatLook.只需拆分字符串。或者使用格式字符串。
System.out.println("Since there are (" + bluerocks
+ ") there must be less than 12 normal rocks");
System.out.printf("Since there are (%d) there must be less than 12 normal rocks",
bluerocks);
System.out.println("Since there are " + bluerocks + " there must be less than 12 normal rocks");
System.out.format("Since there are %d there must be less than 12 normal rocks \n", bluerocks);
System.out.printf("Since there are %d there must be than 12 normal rocks%n", bluerocks);
System.out.print("Since there are ");
System.out.print(bluerocks);
System.out.print(" there must be less than 12 normal rocks\n");