Reads a short from console - Java Language Basics

Java examples for Language Basics:Console

Description

Reads a short from console

Demo Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static BufferedReader buffer = new BufferedReader(
            new InputStreamReader(System.in));

    /**//from w  ww.  ja v a  2  s  .  c om
     * Reads a short from console
     * 
     * @return the read short
     * @throws IOException
     *             If an IO error occurs
     */
    public static short readShort() throws IOException {
        return Short.parseShort(buffer.readLine());
    }
}

Related Tutorials