I am unable to take inputs

I use Scanner for inputs and everytime i get exceptions please check my code what is the mistake

public static void main(String args[]) {
Scanner s = new Scanner(System.in);
String str = s.nextLine();
System.out.println(recRes(str,str.length()-1));
}

Error i am getting :

Exception in thread “main” java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at Main.main(Main.java:5)

Try using str = sc.next();

or a better and a faster way to take inputs is using BufferedReader.

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = in.readLine();