You are here: Home / Topics / Java Program to use charAt function in string

Java Program to use charAt function in string

Filed under: Java on 2023-08-23 06:57:40

// Program to explain the following String function :
// char charAt( int where )

class  McharAt
{
public static void main( String args[ ] )
{
 char ch;
 String s1 = "Nils"; 
 
 ch = s1.charAt( 0 );
 System.out.println( " Character at 0 : " + ch );

 ch = "Java".charAt( 3 );
 System.out.println( " Character at 3 : " + ch );
}
}


Output:

 Character at 0 : N
 Character at 3 : a

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.