标签:style blog http color io ar java sp div
import java.io.*; import java.util.Scanner; public class C { public static void main(String []args) throws IOException { String x1,x2; int sum=0; System.out.print("BufferedReader方法\ninput two number:"); //BufferedReader对象只将回车看作输入结束,得到的字符串 BufferedReader myReader=new BufferedReader(new InputStreamReader(System.in)); x1=myReader.readLine(); x2=myReader.readLine(); int a=Integer.parseInt(x1); int b=Integer.parseInt(x2); sum=a+b; System.out.printf("Sum=%d",sum/2); System.out.println("\n\nScanner 方法"); Scanner sc=new Scanner(System.in); int a1,b1; a1=sc.nextInt(); //Scanner对象把回车,空格,tab键都看作输入结束,直接用sc.next()得到的是字符串形式 b1=sc.nextInt(); System.out.print("sum="+(a1+b1)/2); } }
BufferedReader方法-----Scanner方法
标签:style blog http color io ar java sp div
原文地址:http://www.cnblogs.com/fantasy12436109/p/4003408.html