码迷,mamicode.com
首页 > 其他好文 > 详细

Scanner

时间:2017-09-28 22:29:01      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:new   port   blog   min   tor   logs   sys   nbsp   输入   

 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

标签:new   port   blog   min   tor   logs   sys   nbsp   输入   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!