package org.fun.io;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BufferedReaderDemo {
public static void main(String[] args) throws IOException {
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input:");
String str = br.readLine();
System.out.println("msg:" + str);
}
}
package org.fun.io;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AddDemo {
public static void main(String[] args) throws IOException {
BufferedReader buf = null;
buf = new BufferedReader(new InputStreamReader(System.in));
int i = 0;
int j = 0;
String str = null;
boolean flag = true;
while (flag) {
System.out.print("first number:");
str = buf.readLine();
if (str.matches("\\d+")) {
i = Integer.parseInt(str);
flag = false;
} else {
System.out.println("input again:");
}
}
flag = true;
while (flag) {
System.out.print("Second number:");
str = buf.readLine();
if (str.matches("\\d+")) {
j = Integer.parseInt(str);
flag=false;
} else {
System.out.println("input again:");
}
}
System.out.println(i + "+" + j + "=" + (i + j));
}
}