Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print multiple char variables in one line?

Tags:

java

char

So I was just wondering if there was a way to print out multiple char variables in one line that does not add the Unicode together that a traditional print statement does.

For example:

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
like image 594
Kaptain Avatar asked Feb 03 '26 17:02

Kaptain


2 Answers

System.out.println(a+""+b+""+c);

or:

System.out.printf("%c%c%c\n", a, b, c);
like image 127
Oliver Charlesworth Avatar answered Feb 06 '26 07:02

Oliver Charlesworth


You can use one of the String constructors, to build a string from an array of chars.

System.out.println(new String(new char[]{a,b,c}));
like image 28
barjak Avatar answered Feb 06 '26 06:02

barjak