Java Program to find the index of character in a String

Get a String and a character then find where the character occurred first in the string.

Sample Input 1:

Hello l

Sample Output:


Program or Solution

//The Location Of Given Character In A String ...

import java.util.*;

class Program
 public static void main(String args[])
 String word;
 char ch;
 Scanner sc=new Scanner(;

 System.out.println("Enter The Word:");  

 int len1=word.length();
 int i;

 System.out.println("Enter The Character:");; 
 System.out.println("The Location Of Character Is:");
 System.out.println(" "+i);



Program Explanation