How To Take Runtime Input in Java

In this lesson, you will learn how to take input in Java at runtime.
You can take run-time input from console. Below is the code snippet for it.

    class TakeInput
       public static void main(String p[]) throws IOException
          BufferedReader in=new BufferedReader(new InputStreamReader(;
          System.out.print("Enter any no. to add...");
          String str = in.readLine();
          int value = Integer.parseInt(str);
          int sum = value+25;
          System.out.println("Number after addition = "+sum);

Here "in.readLine()" method is used to get the string at run-time as input where in is declared as an object of BufferedReader class.
Integer.parseInt(str) converts the string into an integer number if possible.

3.5 out of 5 based on 12 user ratings