read a string in java

Question 2 :
Write a java program for read a string from keyboard and display it.

Answer :
In this program we accept a string from the keyboard and print that string on the output console.

1:  import java.io.BufferedReader;  
2: import java.io.IOException;
3: import java.io.InputStreamReader;
4: public class ReadStringDemo
5: {
6: public static void main(String args[])throws IOException
7: {
8: BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9: String S;
10: System.out.println("Enter any String ");
11: S = br.readLine();
12: System.out.println("Entered String is : "+S);
13: }
14: }

read a string in java


Ads by Google