You can do this by following these steps: 1. Use the BufferedReader Class and wrap it with the InputStreamReader class.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) //string str = br.readLine(); //for string input int i = Integer.parseInt(br.readLine()); // for Integer Input
2. Now, since the readLine method throws an IOException, you need to catch it. therefore all code will look as follows.
try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) //string str = br.readLine(); //for string input int i = Integer.parseInt(br.readLine()); // for Integer Input }catch(IOException ioe){ ioe.PrintStackTrace(); }
source share