Java character to String -


I tried several versions including several solutions found here on stack overflow, but I always get numbers instead of characters in the console . For homework in my universe, we need to turn the characters in a string. But creating a new string does not seem so easy.

I tried to use stringbillers,

  stringbuilder builder = new stringbiller (); // ... builder.append (c); // c type char  

string completion,

  System.out.print ("" + c); // c type char  

and even String.valueOf (),

  System.out.print (String.valueOf (c) )); // C type four  

and each one of them again with a clear conversion on char . But I get the serial number of the characters in the sequence instead of the actual characters in the form of the output in the console. How can I make a new string correctly from char s?

  / ** * Print Informative - IN0002 * UrbitanBlat 02 - Aufgabe 2.6 (Buchstaben invertieren) * / Public Category H0206 {Public Stabilized String Readline () {Final StringBuilder Builder = New StringBuilder (); Read {// until a new letter is found. While (true) {int c = System.in.read (); Break if (C == '\ n'); Builder.append (c); }} Hold (java.io.IOException e) {; // We believe that the end of the stream was reached. } Return Builder To string (); } Public static zero main (string [] args) {// read the first row from the terminal. Last string input = readline (); // Create lowercase and uppercase version of the line. Last string lowercase = input.toLowerCase (); Last string uppercase = input.toUpperCase (); // convert the string on the fly and print it out. For (int i = 0; i & lt; input.length (); ++ i) {// If the character is similar to lowercase // version, then we will use an uppercase version instead I char c = input CharAt (i); If (lowercase. Chart (I) == C) C = uppercase. Chart (i); System.out.print (Character.toString (c)); } System.out.println (); }}  

Here is the sample code you provide:

  int c = System.in.read (); Break if (C == '\ n'); Builder.append (c);  

The way you call, it will be called. As Javadok says, "The overall effect is exactly the same as the argument was changed into string by string.valueoff (int), and the characters of that string were added to this character sequence." Casting the integer-value to four in this way will have the desired behavior:

  int c = System.in.read (); Break if (C == '\ n'); Builder.Append ((four));  

Comments