Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在一行中打印多个字符变量?_Java_Char - Fatal编程技术网

Java 在一行中打印多个字符变量?

Java 在一行中打印多个字符变量?,java,char,Java,Char,所以我想知道是否有一种方法可以在一行中打印出多个char变量,而不像传统的print语句那样将Unicode添加到一起 例如: char a ='A'; char b ='B'; char c ='C'; System.out.println(a+b+c); <--- This spits out an integer of the sum of the characters chara='a'; 字符b='b'; 字符c='c'; 系统输出打印项次(a+b+c); 或: 调用的pr

所以我想知道是否有一种方法可以在一行中打印出多个
char
变量,而不像传统的print语句那样将Unicode添加到一起

例如:

char a ='A'; 
char b ='B'; 
char c ='C';
System.out.println(a+b+c); <--- This spits out an integer of the sum of the characters
chara='a';
字符b='b';
字符c='c';
系统输出打印项次(a+b+c);
或:

调用的
println()
方法接受
int
参数

对于类型为
char
的变量和接受
int
的方法,
char
s是
int
s。它们在作为
int
结果返回之前被相加

您需要使用重载的
println()
方法来接受
字符串。要实现这一点,您需要使用
String
串联。在本例中,将
+
运算符与
字符串和任何其他类型的
char
一起使用

System.out.println(a + " " + b + " " + c); // or whatever format

系统输出打印(a);系统输出打印(b);System.out.print(c)//无空格

这将用于:
System.out.println(String.valueOf(a)+String.valueOf(b)+String.valueOf(c))

您可以使用一个字符串构造函数,从字符数组构建字符串

System.out.println(new String(new char[]{a,b,c}));

嗯,那太快了。看起来很简单。谢谢,我会使用StringBuilder而不是笨拙的字符串连接(只是一个首选项),但是printf答案是+1。您想要的是
字符串,而不是将三个字符加在一起。
char
是一个无符号16位整数。
System.out.println(a + " " + b + " " + c); // or whatever format
System.out.println(new StringBuilder(a).append(b).append(c).toString());
System.out.println(new String(new char[]{a,b,c}));