Search Java Programs

Wednesday, January 20, 2010

charAt() Method In Java

Description of program:

Here, you will understand about the procedure of the charAt() method through the following java program. This program reads a string as input through the keyboard. And first this shows the length of the string then find the character at the 4th (mentioned as a parameter of the method) position of the string that is retrieved by using charAt() method. This method takes a parameter that is the position of the string. The charAt() method returns a character value for the character at the given position of the string.

Here is the code of this program:

import java.io.*;
class CharAt{
public static void main(String[] args){
try{
BufferedReader object=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the String");
String s=object.readLine();
int len=s.length();
System.out.println(len);
char char1=s.charAt(4);
System.out.println(char1);
}
catch(Exception e){}
}
Output this program:
C:\java_work>java CharAt
Enter the String
roseindia
9
i

No comments:

Post a Comment

Website Design by Mayuri Multimedia