Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.PushbackInputStream;

import java.io.IOException;

public class Main {
    public static final int ReadInt(PushbackInputStream in) {
        return ReadInt(in, 0);
    }

    public static final int ReadInt(PushbackInputStream in, int def) {
        int b;
        boolean neg = false;
        int i = 0, digits = 0;
        try {
            while (true) {
                b = (int) in.read() & 0xff;
                if (b == '-' && digits == 0)
                    neg = !neg;
                else if (Character.isDigit(b)) {
                    i = 10 * i + (b - (int) '0');
                    ++digits;
                } else if (digits != 0 || !Character.isSpace((char) b)) {
                    if (b != -1)
                        in.unread(b);
                    break;
                }
            }
        } catch (IOException e) {
        }
        try {
            while ((b = in.read()) != '/' && b != -1)
                ;
        } catch (IOException e) {
        }
        if (neg)
            i = -i;
        return digits > 0 ? i : def;
    }
}