Home Java Beginners charAt() Method In Java



charAt() Method In Java
Posted on: June 5, 2007 at 12:00 AM
In this section, you will get the detailed explanation about the charAt() method of String class.

charAt() Method In Java

     

In this section, you will get the detailed explanation about the charAt() method of String class. We are going for using charAt() method. You can see how to use the method by syntax. There is a section provided for understanding the usage of the method practically.

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){}
  }
}

OOutput this program:

C:\java_work>java CharAt
Enter the String
roseindia
9
i
C:\java_work>

Download this example.

Related Tags for charAt() Method In Java:
javacstringkeyboardinputiomethodfindcharkeyreadparameterusingthispositionlengthcharactershowiecteprogramramposprocwssheilitprocedureadsputtriefirstceinasstamntoutpartrososiosiosjadesthroughretrievemehowhrproparamboardsatrackisirhallmeterfolloweaduandaractstrwingvassrocriringrdthshoavstabhatfinboaprndonogrolonp


More Tutorials from this section

Ask Questions?    Discuss: charAt() Method In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.