Programming Tutorials

Comment on Tutorial - indexOf() and lastIndexOf() in Java By Hong



Comment Added by : vallabh

Comment Added at : 2014-10-04 17:44:18

Comment on Tutorial : indexOf() and lastIndexOf() in Java By Hong
u can try this out it will satisify u:)
import java.io.*;
public class lastindexof
{
public static void main(String[] args) throws IOException
{
String mystr;
int cou=0;
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("enter the string");
mystr=bf.readLine();
System.out.println("enter the string ");
String st=bf.readLine();
for(int i=0;i<mystr.length()-1;i++)
{
if(mystr.indexOf(st)!=-1)
cou++;
}
System.out.println(" character at position is=" +mystr.indexOf(st));
System.out.println(cou);;
}
}


View Tutorial