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:Main.java
public static void main(String[] ap) { int val; try {/*from ww w .j ava2 s . c om*/ Scanner sc = new Scanner(System.in); // Requires J2SE 1.5 val = sc.nextInt(); } catch (NumberFormatException ex) { System.err.println("Not a valid number: " + ex); return; } System.out.println("I read this number: " + val); }
From source file:Main.java
public static void main(String[] arg) { System.out.println("Type something"); try {//from www . j a va2 s . c o m System.in.read(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from ww w . j a v a 2s. c o m while (true) { int datum = System.in.read(); if (datum == -1) break; System.out.println(datum); } } catch (IOException ex) { System.err.println("Couldn't read from System.in!"); } }
From source file:MainClass.java
public static void main(String args[]) { Scanner input = new Scanner(System.in); int number1;/*w w w .j a v a 2s.c o m*/ int number2; System.out.print("Enter first integer: "); // prompt number1 = input.nextInt(); // read first number from user System.out.print("Enter second integer: "); // prompt number2 = input.nextInt(); // read second number from user if (number1 == number2) System.out.printf("%d == %d\n", number1, number2); if (number1 != number2) System.out.printf("%d != %d\n", number1, number2); if (number1 < number2) System.out.printf("%d < %d\n", number1, number2); if (number1 > number2) System.out.printf("%d > %d\n", number1, number2); if (number1 <= number2) System.out.printf("%d <= %d\n", number1, number2); if (number1 >= number2) System.out.printf("%d >= %d\n", number1, number2); }
From source file:Main.java
public static void main(String[] args) { System.out.println("Enter a string"); Scanner input = new Scanner(System.in); String s1 = input.nextLine(); s1 = s1.trim();/*ww w. j a v a 2s.c o m*/ int howLong = s1.length(); for (int counter = 0; counter < howLong; counter++) { char ch = s1.charAt(counter); System.out.print(ch); } }
From source file:MainClass.java
public static void main(String args[]) { Scanner conin = new Scanner(System.in); int count = 0; double sum = 0.0; System.out.println("Enter numbers to average."); while (conin.hasNext()) { if (conin.hasNextDouble()) { sum += conin.nextDouble();//from ww w . ja va2s. c o m count++; } else { String str = conin.next(); if (str.equals("done")) break; else { System.out.println("Data format error."); return; } } } System.out.println("Average is " + sum / count); }
From source file:Main.java
public static void main(String[] args) throws Exception { System.setIn(new FileInputStream("file.txt")); char ret = (char) System.in.read(); System.out.println(ret);//from www .jav a 2s . c om }
From source file:MainClass.java
public static void main(String[] args) { try {// w w w. j a va 2 s . c om System.out.println("In second try block in main()"); System.in.read(); return; } catch (IOException e) { System.out.println("I/O exception caught in main()"); } finally { System.out.println("finally block for second try block in main()"); } System.out.println("Code after second try block in main()"); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream in = System.in; BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt")); int letter;//from ww w .ja v a 2 s . c o m while ((letter = in.read()) != -1) { bw.write((char) letter); bw.flush(); } }
From source file:MainClass.java
public static void main(String[] args) { try {//from w w w. j ava 2 s . c om copy(System.in, System.out); } catch (IOException ex) { System.err.println(ex); } }