Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- public class modScanner {
- private Reader reader;
- private char lastChar;
- private StringBuilder string = new StringBuilder("");
- private StringBuilder integer = new StringBuilder("");
- private boolean used = false;
- public modScanner(Reader r) {
- reader = r;
- }
- // public modScanner(InputStream in) {
- // this(new BufferedReader(new InputStreamReader(in)));
- // }
- public modScanner(File file) throws IOException {
- this(new BufferedReader(new FileReader(file)));
- }
- public void close() throws IOException {
- reader.close();
- }
- private boolean nextSymbolReader() throws IOException {
- int ch = reader.read();
- if (ch >= 0) {
- lastChar = (char) ch;
- return true;
- }
- return false;
- }
- private boolean createString() throws IOException {
- if (!used) {
- string.delete(0, string.length());
- while (nextSymbolReader() && !Character.isWhitespace(lastChar)) {
- string.append(lastChar);
- }
- return string.length() > 0;
- }
- return string.length() > 0;
- }
- private boolean createStringInt() throws IOException {
- if (!used) {
- integer.delete(0, integer.length());
- while (nextSymbolReader() && !Character.isWhitespace(lastChar) && (Character.isDigit(lastChar) || lastChar == '.')) {
- integer.append(lastChar);
- }
- if (integer.length() > 0 && integer.charAt(integer.length() - 1) == '.'){
- createStringInt();
- }
- return integer.length() > 0;
- }
- return integer.length() > 0;
- }
- public boolean hasNext() throws IOException {
- if (used) {
- used = false;
- return createString();
- }
- return createString();
- }
- public boolean hasNextInt() throws IOException {
- if (used) {
- used = false;
- return createStringInt();
- }
- return createStringInt();
- }
- public String next() throws IOException {
- used = true;
- return string.toString();
- }
- public int nextInt() throws IOException {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement