Sunday 3 April 2011

How to Convert Character into a String in java

import java.io.*;
import java.lang.*;
/*
This program takes a character at the console and converts it into a string format using by the toString() method. This method converts the character into an integer type data. The character class wraps a value of the primitive type char in an object. The toString method returns a string object representing this character's values
*/


public class CharToString{
public static void main(String args[])throws IOException{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Character:");
String s = read.readLine();
char c = s.charAt(0);
System.out.println("Character value is " + c);
String s1 = Character.toString(c);
System.out.println("String value is " + s1);
}
}

Output of this program.

C:\corejava>java CharToString
Enter a Character:
R
Character value is R
String value is R
C:\corejava>

1 comment:

  1. Hi,Once done with the planning and designing of the solution to be proposed comes the actual implementation process with Web Design Cochin. In this after a design has been finalized comes the process of programming. At this level features like Login and Shopping cart are inculcated.web,Thanks..........

    ReplyDelete