How to take Character Input in Java using BufferedReader ClassIn Java, the Scanner class is used to take character input from the user. The Scanner class is not a single solution of taking character input from the user. The BufferedReader class an alternative to the Scanner class for taking character input from the user. Let's start understanding how to take character input in Java using BufferedReader. These are the following steps to take character input using BufferedReader:
Let's take some example to understand how the BufferedReader class is used to read character data in Java. We will take two examples, i.e., BufferedReaderExample and BufferedReaderExample2. In the first example, we will simply read the character data using the BufferedReader class and print it to the screen. In the second example, we will get the string from user using BufferedReader class and perform some operations on the user entered string. BufferedReaderExample.java Output BufferedReader class can also be used to get the string from the user. For this, we will use the readLine() of the BufferedReader class. Let's understand it by taking another example of BufferedReader. We will calculate the area of the triangle by taking its base value and height value from the user as a string using BufferedReader class. We then convert the string data into a double by parsing string data, and then we calculate the area of the triangle by using the formula (base*height)/2. BufferedReaderExample2.java Output Next TopicJava employee details program |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India