1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
/* Read line of characters from console using InputStream This example shows how to read a line or string from console window using readLine method of BufferedInputStream. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ReadLineFromConsoleExample { public static void main(String[] args) { /* * To read line or string from console use, * readLine method of BufferedReader class. */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String strLine = null; System.out.println("Reading line of characters from console"); System.out.println("Enter exit to quit"); try { while( (strLine = br.readLine()) != null) { if(strLine.equals("exit")) break; System.out.println("Line entered : " + strLine); } br.close(); } catch(Exception e) { System.out.println("Error while reading line from console : " + e); } } } |
how to get this ouput from following input?
input:String i=”aaabccccdd”;
output:a3bc4d2