import java.io.*;
import java.util.*;
public class Place{
String string, index;
char character;
Scanner scan=new Scanner(System.in);
public void input(){
try{
System.out.println("Enter any String: ");
string=scan.nextLine();
System.out.println("Enter any character to display its Index number: ");
index=scan.nextLine();
character=index.charAt(0);
}
catch(Exception e){
System.out.println("Error Code: "+e);
System.exit(0);
}
}
public void compute(){
System.out.println("First Index of \""+character+"\" is: "+(string.indexOf(character))+"\nLast Index of \""+character+"\" is: "+(string.lastIndexOf(character)));
}
public static void main(String[] args){
Place obj=new Place();
obj.input();
obj.compute();
}
}
import java.util.*;
public class Place{
String string, index;
char character;
Scanner scan=new Scanner(System.in);
public void input(){
try{
System.out.println("Enter any String: ");
string=scan.nextLine();
System.out.println("Enter any character to display its Index number: ");
index=scan.nextLine();
character=index.charAt(0);
}
catch(Exception e){
System.out.println("Error Code: "+e);
System.exit(0);
}
}
public void compute(){
System.out.println("First Index of \""+character+"\" is: "+(string.indexOf(character))+"\nLast Index of \""+character+"\" is: "+(string.lastIndexOf(character)));
}
public static void main(String[] args){
Place obj=new Place();
obj.input();
obj.compute();
}
}
Comments