Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Input-loop/Java/input-loop-1.java
Normal file
25
Task/Input-loop/Java/input-loop-1.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InputLoop {
|
||||
public static void main(String args[]) {
|
||||
// To read from stdin:
|
||||
InputStream source = System.in;
|
||||
|
||||
/*
|
||||
Or, to read from a file:
|
||||
InputStream source = new FileInputStream(filename);
|
||||
|
||||
Or, to read from a network stream:
|
||||
InputStream source = socket.getInputStream();
|
||||
*/
|
||||
|
||||
Scanner in = new Scanner(source);
|
||||
while(in.hasNext()){
|
||||
String input = in.next(); // Use in.nextLine() for line-by-line reading
|
||||
|
||||
// Process the input here. For example, you could print it out:
|
||||
System.out.println(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Task/Input-loop/Java/input-loop-2.java
Normal file
31
Task/Input-loop/Java/input-loop-2.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
public class InputLoop {
|
||||
public static void main(String args[]) {
|
||||
// To read from stdin:
|
||||
Reader reader = new InputStreamReader(System.in);
|
||||
|
||||
/*
|
||||
Or, to read from a file:
|
||||
Reader reader = new FileReader(filename);
|
||||
|
||||
Or, to read from a network stream:
|
||||
Reader reader = new InputStreamReader(socket.getInputStream());
|
||||
*/
|
||||
|
||||
try {
|
||||
BufferedReader inp = new BufferedReader(reader);
|
||||
while(inp.ready()) {
|
||||
int input = inp.read(); // Use in.readLine() for line-by-line
|
||||
|
||||
// Process the input here. For example, you can print it out.
|
||||
System.out.println(input);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// There was an input error.
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue