List of usage examples for java.io InputStreamReader InputStreamReader
public InputStreamReader(InputStream in)
From source file:Main.java
public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String text = "q"; while (true) { System.out.print("Please type a message (Q/q to quit) and press enter:"); text = br.readLine();//from w w w . ja va2 s.c o m if (text.equalsIgnoreCase("q")) { System.out.println("We have decided to exit the program"); break; } else { System.out.println("We typed: " + text); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { System.out.print("Enter your name: "); InputStreamReader reader = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(reader); String name = in.readLine();//from ww w.j a va2s. c om System.out.println("Hello, " + name + ". Enter three ints..."); int[] values = new int[3]; double sum = 0.0; for (int i = 0; i < values.length; i++) { System.out.print("Number " + (i + 1) + ": "); String temp = in.readLine(); values[i] = Integer.parseInt(temp); sum += values[i]; } System.out.println("The average equals " + sum / values.length); }
From source file:UseTrim.java
public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str;//from ww w . ja v a 2 s. c o m System.out.println("Enter 'stop' to quit."); System.out.println("Enter letter: "); do { str = br.readLine(); str = str.trim(); if (str.equals("I")) System.out.println("I"); else if (str.equals("M")) System.out.println("M"); else if (str.equals("C")) System.out.println("C."); else if (str.equals("W")) System.out.println("W"); } while (!str.equals("stop")); }
From source file:ParseDemo.java
public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str;//from ww w. jav a 2 s. c om int i; int sum = 0; System.out.println("Enter numbers, 0 to quit."); do { str = br.readLine(); try { i = Integer.parseInt(str); } catch (NumberFormatException e) { System.out.println("Invalid format"); i = 0; } sum += i; System.out.println("Current sum is: " + sum); } while (i != 0); }
From source file:TinyEdit.java
public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = new String[100]; System.out.println("Enter lines of text."); System.out.println("Enter 'stop' to quit."); for (int i = 0; i < 100; i++) { str[i] = br.readLine();/* w w w.j a v a2 s. c om*/ if (str[i].equals("stop")) break; } System.out.println("\nHere is your file:"); for (int i = 0; i < 100; i++) { if (str[i].equals("stop")) break; System.out.println(str[i]); } }
From source file:MainClass.java
public static void main(String args[]) { try {/* www .j av a2 s .c om*/ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); while (true) { System.out.print("Radius? "); String str = br.readLine(); double radius; try { radius = Double.valueOf(str).doubleValue(); } catch (NumberFormatException nfe) { System.out.println("Incorrect format!"); continue; } if (radius <= 0) { System.out.println("Radius must be positive!"); continue; } double area = Math.PI * radius * radius; System.out.println("Area is " + area); return; } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String strLine = in.readLine(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); out.write(strLine, 0, strLine.length()); out.flush();//from w ww . j ava 2 s.c om in.close(); out.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:1776"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line;/*from ww w. j a v a 2 s .c om*/ while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); }
From source file:Main.java
public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String tmp = br.readLine();//www . j a v a 2s .c om int length = tmp.length(); char c[] = new char[length]; tmp.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); int i; System.out.print("input1 is:"); while ((i = input1.read()) != -1) { System.out.print((char) i); } }
From source file:Main.java
public static void main(String args[]) throws IOException { String data, answer = ""; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter any String : "); data = br.readLine();/*from w ww. j a v a2s .c o m*/ char[] findupper = data.toCharArray(); for (int i = 0; i < findupper.length; i++) { if (findupper[i] >= 65 && findupper[i] <= 91) // ascii value in between 65 // and 91 is A to Z { answer += findupper[i]; // adding only uppercase } } System.out.println("Answer : " + answer); }