博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Scanner 输入---从键盘输入两个数进行相加
阅读量:7223 次
发布时间:2019-06-29

本文共 789 字,大约阅读时间需要 2 分钟。

1 import java.util.Scanner;//scanner 是包含在Java.util中的;使用的时候需要调用 2  3 /** 4  * 测试Scanner类的使用、如何接受键盘的输入 5  * @author ZBG34854 6  * 7  */ 8 public class TestScanner { 9     public static void test01(){10         Scanner s = new Scanner(System.in);11         String str = s.next();//程序运行到next会阻塞,等待键盘的输入;12         System.out.println("刚才键盘输入:"+str);13     }14     public static void test02(){15         Scanner s = new Scanner(System.in);16         System.out.println("请输入一个加数:");17         int a = s.nextInt();18         System.out.println("请输入被加数:");19         int b = s.nextInt();20         int sum = a + b;21         System.out.println("计算结果:"+sum);22     }23     public static void main(String[] args){24         test02();25     }26 27 }

 

转载于:https://www.cnblogs.com/zbgghost/p/8451793.html

你可能感兴趣的文章
Unity3D插件大全
查看>>
c++中打乱数组的顺序输出
查看>>
极速理解设计模式系列:8.策略模式(Strategy Pattern)
查看>>
Hyper-V Server --SMB3.0
查看>>
IT草根的江湖之路之五:鉴于现实,屈服!
查看>>
编译报错 /usr/bin/ld: cannot find -lc 解决
查看>>
系统自带的系统工具
查看>>
浅谈专心只学一门C#的优缺点[邀月补充:一精胜于十专]
查看>>
UWA资源检测与分析支持Unity 5.3!
查看>>
IOT
查看>>
记录一次raid故障后的恢复和回迁数据全过程
查看>>
单臂路由的配置
查看>>
Operations Manager 2007 R2系列之邮件通知
查看>>
被动DNS
查看>>
需求管理之客户需求何时休?
查看>>
crs_register ora.<node>.LISTENER_<node>.lsnr.cap
查看>>
ghld data format
查看>>
VMM系列之使用VMM服务器构建 Hyper-V主机(4)
查看>>
Application Virtualization 4.5 部署之四独立模式
查看>>
linux sed命令详解
查看>>