List of usage examples for java.lang System in
InputStream in
To view the source code for java.lang System in.
Click Source Link
From source file:ReadConsole.java
public static void main(String args[]) throws Exception { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s;//from ww w . ja va 2 s .c o m while ((s = br.readLine()) != null) { System.out.println(s.length()); } isr.close(); }
From source file:MainClass.java
public static void main(String[] args) { int inChar;//from w ww . j av a2 s .c o m System.out.println("Enter a Character:"); try { inChar = System.in.read(); System.out.print("You entered "); System.out.println(inChar); } catch (IOException e) { System.out.println("Error reading from user"); } }
From source file:ReverseConsoleInput.java
public static void main(String args[]) throws Exception { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); // Read and process lines from console String s;// w w w . j a v a 2 s. c o m while ((s = br.readLine()) != null) { StringBuffer sb = new StringBuffer(s); sb.reverse(); System.out.println(sb); } isr.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); while (true) { System.out.print("Radius? "); String str = br.readLine(); double radius; try {/*from w ww . j a va 2 s.c o m*/ 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; } System.out.println("radius " + radius); return; } }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String input = reader.readLine(); double number = Double.parseDouble(input); System.out.println(input + ":" + Math.sqrt(number)); reader.close();//from w w w .ja v a 2 s .c om }
From source file:Calculator.java
public static void main(String[] args) { System.out.println("type something like: 1+3"); Scanner scanner = new Scanner(System.in); double n1 = Double.NaN; double n2 = Double.NaN; String operation = null;/* w w w . ja va2s. c o m*/ try { n1 = scanner.nextDouble(); operation = scanner.next(); n2 = scanner.nextDouble(); double result = calculate(n1, n2, operation); System.out.printf("%s %s %s = %.2f%n", n1, operation, n2, result); } catch (Exception e) { System.out.println("An invalid expression."); } }
From source file:EchoStdin.java
public static void main(String[] args) throws IOException { System.out.print("Please type a message and press enter: "); int c = '\n'; while ((c = System.in.read()) != '\n') { System.out.print((char) c); }/*from w w w .j a v a 2s . co m*/ }
From source file:Test.java
public static void main(String[] args) { try {// w w w . j a v a2 s . c om System.out.print("Enter a number: "); int number = new Scanner(System.in).nextInt(); if (number < 0) { throw new InvalidParameter(); } System.out.println("The number is: " + number); } catch (InputMismatchException | InvalidParameter e) { System.out.println("Invalid input, try again"); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a line:"); System.out.println(stdin.readLine()); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s;//from w w w .j a v a2s. co m while ((s = in.readLine()) != null && s.length() != 0) System.out.println(s); // An empty line or Ctrl-Z terminates the program }