返回列表

java输入输出

默认分类 2013-03-07 14:31:46

C:\Java\workspace g\src\clazz\In.java

package clazz;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class In {

    public static void main(String[] args) throws NumberFormatException, IOException {
        //关键 抛出异常
        int i = 0;
        int j = 0;
        BufferedReader br = null;

        System.out.println("请输入值1:");
        br = new BufferedReader(new InputStreamReader(System.in));//关键 从键盘读入
        i = Integer.parseInt(br.readLine()); //关键 将值付给i

        System.out.println("请输入值2:");
        br = new BufferedReader(new InputStreamReader(System.in)); //关键

        j = Integer.parseInt(br.readLine()); //关键

        System.out.print(String.valueOf(i));
        System.out.print(" + ");
        System.out.print(String.valueOf(j));
        System.out.print(" = ");
        System.out.println(String.valueOf(i+j));
        System.out.println("==========================");

    }

}