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:MainClass.java
public static void main(String args[]) { try {//w ww . j a v a 2s . 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 ww w. j a v a2 s.c o m*/ in.close(); out.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();/*from w w w .ja v a2 s .c o m*/ 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 w w . java 2s. 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); }
From source file:Main.java
public static void main(String[] ap) { String line = null;//from w w w. j ava2s . c o m int val = 0; try { BufferedReader is = new BufferedReader(new InputStreamReader(System.in)); line = is.readLine(); val = Integer.parseInt(line); } catch (NumberFormatException ex) { System.err.println("Not a valid number: " + line); } catch (IOException e) { System.err.println("Unexpected IO ERROR: " + e); } System.out.println("I read this number: " + val); }
From source file:Main.java
public static void main(String[] args) { String str = "java2s.com"; ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes()); System.setIn(bais);/* ww w. ja v a2 s . c om*/ Scanner scanner = new Scanner(System.in); String input = scanner.next(); System.out.println(input); }
From source file:MainClass.java
public static void main(String args[]) { try {//w w w . j a v a 2 s .c o m System.out.print("Enter your name: "); InputStreamReader reader = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(reader); String name = in.readLine(); 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); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) throws IOException { BufferedReader inData = new BufferedReader(new InputStreamReader(System.in)); StreamTokenizer inStream = new StreamTokenizer(inData); inStream.commentChar('#'); boolean eof = false; do {//www. j a v a2s.c om int token = inStream.nextToken(); switch (token) { case StreamTokenizer.TT_EOF: System.out.println("EOF encountered."); eof = true; break; case StreamTokenizer.TT_EOL: System.out.println("EOL encountered."); break; case StreamTokenizer.TT_WORD: System.out.println("Word: " + inStream.sval); break; case StreamTokenizer.TT_NUMBER: System.out.println("Number: " + inStream.nval); break; default: System.out.println((char) token + " encountered."); if (token == '!') eof = true; } } while (!eof); }
From source file:Main.java
public static void main(String[] av) throws IOException { StreamTokenizer tf = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int i;// w w w .jav a 2s .com while ((i = tf.nextToken()) != StreamTokenizer.TT_EOF) { switch (i) { case StreamTokenizer.TT_EOF: System.out.println("End of file"); break; case StreamTokenizer.TT_EOL: System.out.println("End of line"); break; case StreamTokenizer.TT_NUMBER: System.out.println("Number " + tf.nval); break; case StreamTokenizer.TT_WORD: System.out.println("Word, length " + tf.sval.length() + "->" + tf.sval); break; default: System.out.println("What is it? i = " + i); } } }
From source file:StreamTokenApp.java
public static void main(String args[]) throws IOException { BufferedReader inData = new BufferedReader(new InputStreamReader(System.in)); StreamTokenizer inStream = new StreamTokenizer(inData); inStream.commentChar('#'); boolean eof = false; do {/*from w w w . j a v a 2 s . co m*/ int token = inStream.nextToken(); switch (token) { case inStream.TT_EOF: System.out.println("EOF encountered."); eof = true; break; case inStream.TT_EOL: System.out.println("EOL encountered."); break; case inStream.TT_WORD: System.out.println("Word: " + inStream.sval); break; case inStream.TT_NUMBER: System.out.println("Number: " + inStream.nval); break; default: System.out.println((char) token + " encountered."); if (token == '!') eof = true; } } while (!eof); }