Try these using `stdin.hasNext()`
import java.io.BufferedInputStream;
import java.util.Scanner;
public class ReadMultiline {
public static void main(String args[]) {
Scanner stdinput = new Scanner(new BufferedInputStream(System.in));
while (stdinput.hasNext()) {
System.out.println(Math.abs(stdinput.nextLong() -
stdinput.nextLong()));
String s=scanner.next();
}
}
}
I'd use some Java 8 tricks.
public static String streamToString(final InputStream inputStream) throws Exception {
// buffering optional
try
(
final BufferedReader br
= new BufferedReader(new InputStreamReader(inputStream))
) {
// parallel optional
return br.lines().parallel().collect(Collectors.joining("\n"));
} catch (final IOException e) {
throw new RuntimeException(e);
// whatever.
}
}
Essentially the same as some other answers except more succinct.