集册 Java实例教程 从控制台读取Int和String

从控制台读取Int和String

欢马劈雪     最近更新时间:2020-01-02 10:19:05

549
从控制台读取Int和String
/**from 时代Java公众号 - N o w J a  v a . c o m**/

//package com.nowjava;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;


public class Main {

    public static void main(String[] argv) throws Exception {

        System.out.println(readInt());

    }


    private static BufferedReader bufferedReader = new BufferedReader(

            new InputStreamReader(System.in));


    public static int readInt() {

        int i;

        /** from 
        时代Java公众号**/

        try {

            i = Integer.parseInt(readString());

        } catch (NumberFormatException nfe) {

            i = readInt();

        }


        return i;

    }


    public static String readString() {

        String s = "";


        try {

            s = bufferedReader.readLine();

        } catch (IOException io) 
展开阅读全文