-1
enter code here
    import java.io.*;
    class Index
    {
    public static void main(String str[]) throws IOException
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter a String");
    String a = br.readLine();
    System.out.println("\nEnter the Character you want to search for : ");
    char ch =(char) br.read();
    int chr = a.indexOf(ch);
    System.out.println("\nCharcter "+ch+ " is found at location :" +chr);
    System.out.println("\n Enter the location and let's see what charcter is present at that 
     location");
    int b = Integer.parseInt(br.readLine());
    }
    }

As soon as the last statement is coming to execution it is throwing Run-Time Error

    Exception in thread "main" java.lang.NumberFormatException: For input string: " "
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
    at java.base/java.lang.Integer.parseInt(Integer.java:646)
    at java.base/java.lang.Integer.parseInt(Integer.java:778)
    at Index.main(Index.java:18)

Where I am going wrong?

Ajay9
  • 1

0 Answers0