Last active
November 18, 2018 13:02
-
-
Save code-n-roll/1c7106121eee082e87e30304f0a2c6c1 to your computer and use it in GitHub Desktop.
Started code of Input/Output on Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class Solution { | |
public static void main(String[] args) { | |
InputStream inputStream = System.in; | |
OutputStream outputStream = System.out; | |
InputReader in = new InputReader(inputStream); | |
PrintWriter out = new PrintWriter(outputStream); | |
Task solver = new Task(); | |
solver.solve(in, out); | |
out.close(); | |
} | |
static class Task { | |
public void solve(InputReader in, PrintWriter out) { | |
// in.next() - read string separated by whitespaces or line feed | |
// in.nextLine() - read string separated by line feed (\n) | |
// in.nextInt() - read integer separated by whitespaces or line feed | |
// in.nextLong() - read long separated by whitespaces or line feed | |
// in.nextDouble() - read double separated by whitespaces or line feed | |
// in.nextBigInt() - read big integer separated by whitespaces or line feed | |
// in.nextBigDec() - read big decimal separated by whitespaces or line feed | |
// construction for read unknown count of input lines | |
String input; | |
do { | |
input = in.nextLine(); | |
} while(in.hasNext()); | |
} | |
} | |
static class InputReader { | |
private BufferedReader reader; | |
private StringTokenizer tokenizer; | |
public InputReader(InputStream stream) { | |
reader = new BufferedReader(new InputStreamReader(stream), 32768); | |
tokenizer = null; | |
} | |
public String next() { | |
while (tokenizer == null || !tokenizer.hasMoreTokens()) { | |
try { | |
tokenizer = new StringTokenizer(reader.readLine()); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
return tokenizer.nextToken(); | |
} | |
public int nextInt() { | |
return Integer.parseInt(next()); | |
} | |
public long nextLong() { | |
return Long.parseLong(next()); | |
} | |
public double nextDouble() { | |
return Double.parseDouble(next()); | |
} | |
public BigInteger nextBigInt() { | |
return new BigInteger(next()); | |
} | |
public BigDecimal nextBigDec() { | |
return new BigDecimal(next()); | |
} | |
public String nextLine() { | |
String str = ""; | |
try { | |
str = reader.readLine(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return str; | |
} | |
public boolean hasNext() { | |
try { | |
return reader.ready(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment