一、设计思想
通过在控制台输入两数,定义两个buffer类,用来替换输入的两数。然后在主方法中进行两数的相加。最后输出正确的结果。
二、源代码:
1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 public class Plus { 5 public static void main(String args[]) throws IOException{ 6 System.out.println("Input a b:"); 7 double a; 8 BufferedReader reader1 = new BufferedReader(new InputStreamReader(System.in)); 9 String read1=reader1.readLine(); 10 a=Double.parseDouble(read1); 11 double b; 12 BufferedReader reader2 = new BufferedReader(new InputStreamReader(System.in)); 13 String read2=reader2.readLine(); 14 b=Double.parseDouble(read2); 15 double plus; 16 plus = a + b; 17 /*Output the result*/ 18 System.out.println("a + b = "+plus); 19 }}
三、结果截图