首页 > 其他 > 详细

Scanner

时间:2017-09-28 22:12:17      阅读:326      评论:0      收藏:0      [点我收藏+]
 1 import java.util.Scanner;
 2 
 3 /**
 4  * 测试 Scanner类的使用,如何接受键盘的输入.
 5  * @author Administrator
 6  *@version 1.0
 7  */
 8 public class TestScanner {
 9     
10     public static void test01(){
11         Scanner s=new Scanner(System.in);
12         String str=s.next();//程序运行到next会阻塞,等待键盘输入.
13         System.out.println("刚才输入的是:"+str);
14         
15     }
16     public static void test02(){
17         Scanner s=new Scanner(System.in);
18         
19         System.out.println("请输入一个加数");
20         int a= s.nextInt();
21         System.out.println("请输入一个被加数");
22         int b= s.nextInt();
23         int sum=a+b;
24         System.out.println("计算结果 和为:"+sum);
25         
26     }
27     public static void main(String[] args) {
28         test02();
29     }
30 }

 

Scanner

原文:http://www.cnblogs.com/PoeticalJustice/p/7608772.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!