Last active
September 15, 2015 09:51
-
-
Save rkkautsar/a9926fdd9ecd14edf213 to your computer and use it in GitHub Desktop.
BufferedReader wrapper class
This file contains hidden or 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
class Reader { | |
static BufferedReader br; | |
static InputStreamReader isr; | |
static StringTokenizer tokenizer=new StringTokenizer(""); | |
static String buffer; | |
public Reader(){ | |
isr = new InputStreamReader(System.in); | |
br = new BufferedReader(isr); | |
} | |
public Reader(InputStream input){ | |
isr = new InputStreamReader(input); | |
br = new BufferedReader(isr); | |
} | |
boolean hasNext() throws IOException{ | |
if(tokenizer.hasMoreTokens()) return true; | |
else { | |
buffer = br.readLine(); | |
if(buffer == null || buffer.length()==0) return false; | |
else { | |
tokenizer = new StringTokenizer(buffer); | |
return true; | |
} | |
} | |
} | |
String next() throws IOException{ | |
while(!tokenizer.hasMoreTokens()){ | |
buffer = br.readLine(); | |
tokenizer = new StringTokenizer(buffer); | |
} | |
return tokenizer.nextToken(); | |
} | |
public int nextInt() throws IOException{ | |
return Integer.parseInt(next()); | |
} | |
public double nextDouble() throws IOException{ | |
return Double.parseDouble(next()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment