- 浏览: 6307225 次
- 性别:
- 来自: 一片神奇的土地
文章分类
- 全部博客 (745)
- JQuery (25)
- JS (33)
- 数据库 (59)
- Java基础 (56)
- JSON (8)
- XML (8)
- ireport (7)
- 设计模式 (10)
- 心情 (14)
- freemarker (1)
- 问题 (15)
- powerdesigner (2)
- CSS (15)
- DWR (4)
- tomcat (16)
- Hibernate (12)
- Oracle (7)
- Struts (7)
- Spring (34)
- JSP (23)
- 需学习 (64)
- 工具类库 (63)
- Maven (14)
- 笔试题 (34)
- 源码学习 (31)
- 多线程 (39)
- Android (32)
- 缓存 (20)
- SpringMVC (14)
- jQueryEasyUi (12)
- webservice-RPC (13)
- ant (1)
- ASP.NET (10)
- 正则表达式 (3)
- Linux (15)
- JBoss (1)
- EJB (3)
- UML (2)
- JMS (3)
- Flex (8)
- JSTL (2)
- 批处理 (5)
- JVM (16)
- 【工具】 (16)
- 数据结构 (29)
- HTTP/TCP/Socket (18)
- 微信 (1)
- tomcat源码学习 (15)
- Python (30)
- 主机 (2)
- 设计与架构 (19)
- thrift-RPC (2)
- nginx (6)
- 微信小程序 (0)
- 分布式+集群 (12)
- IO (1)
- 消息队列 (4)
- 存储过程 (8)
- redis (9)
- zookeeper (5)
- 海量数据 (5)
最新评论
-
360pluse:
技术更新,战术升级!Python爬虫案例实战从零开始一站通网盘 ...
Python爬虫实战:Scrapy豆瓣电影爬取 -
18335864773:
推荐用 pageoffice 组件生成 word 文件。
JAVA生成WORD工具类 -
jjhe369:
LISTD_ONE 写道起始地址为163.135.0.1 结束 ...
IP地址与CIDR -
baojunhu99:
private final int POOL_SIZE = 5 ...
使用CompletionService获取多线程返回值 -
LovingBaby:
胡说,javascript 运行时是单线程的,event lo ...
Ajax请求是否可以实现同步
system.in.read()方法的作用是从键盘读出一个字符,然后返回它的Unicode码。按下Enter结束输入
看一下这个程序:
for(int j = 0; j < 5; j++) { System.out.println("INPUT:"); char c = 0; try { c = (char) System.in.read(); } catch(IOException e){ } if( c == '1') { System.out.println("OK!"); } }
假设我们输入1,结果:
INPUT:
1
OK!
INPUT:
INPUT:
INPUT:
啥原因?
一点一点Debug我们会发现,第二次时读到的字符其实是回车符\t,继续循环;第三次接受到的是换行符\n,也继续循环;第三次到Input出不动,等待我们继续循环。
第二次:
结论:
用System.in.read()时,我们在键盘上按下的任何一个键都会被当做是输入值,包括Enter键也会被当做是一个值!当我们按下Enter的时候,实际上发送两个键值:一个回车\t(13),一个是换行\n(10)
参考:http://www.360doc.com/content/07/1112/13/15458_818134.shtml
例子2 :
public static void main(String[] args) { try { int i=System.in.read(); System.out.println(i); } catch (IOException e) { e.printStackTrace(); } }
这里输入1,这返回结果是49
输入A,返回结果是65
例子3:
public static void main(String[] args) throws Exception { int[] x = new int[6]; Arrays.fill(x, 1); for (int i = 0; i < x.length; i++) { System.in.read(); System.out.println(x[i]); } }
结果:
输出1 1 1 后等待输入
发表评论
-
拦截器和过滤器的区别
2019-06-27 10:46 7005【Spring的拦截器】于【Servlet的Filter】有 ... -
高并发下的数据结构List/Set/Map
2019-03-26 14:17 1218高并发下的Java数据结 ... -
AQS
2019-03-21 15:08 2029大白话聊聊Java并发面试问题之谈谈你对AQS的理解? ... -
tomcat的三种运行模式+JAVA NIO
2019-03-12 11:13 5010详解Tomcat三种运行模 ... -
反射基础
2019-01-11 14:51 621十年架构师不到400行手写一个Spring MVC ... -
java反射原理, 注解原理
2019-01-08 17:22 4537注解机制及原理 JAVA ... -
内存泄露与内存溢出的区别
2018-12-24 16:14 26931、内存泄漏 memory le ... -
深入解析JAVA中的装箱与拆箱
2018-12-21 10:42 1254地址: https://www.cnblogs.com/d ... -
负载均衡原理
2018-12-20 17:43 748简介几种负载均衡原理 高并发解决方案之一 ——负载均衡 ... -
CAS自旋锁
2018-12-20 11:12 1572我们常说的 CAS 自旋锁是什么 CAS与ABA问题 ... -
HTTP-断点续传和多线程下载
2018-08-23 14:17 4595HTTP断点续传 Range:客户端发请求的范围 ... -
tcp粘包和拆包的处理方案
2018-08-23 11:03 7887tcp粘包和拆包的处理方案 产生tcp ... -
TCP如何保证传输可靠性
2018-08-22 15:51 9937TCP 滑动窗口和 拥塞 ... -
【JVM命令及问题排查】
2018-08-21 16:06 1819java中的gc log解读 eclipse的优化 gc ... -
【HTTP1.0 HTTP 1.1 HTTP 2.0主要区别】长头域+多复数压推
2018-08-20 14:53 1101HTTP/2.0 相比1.0有哪些 ... -
MVCC
2018-08-20 10:34 3482轻松理解MYSQL MVCC 实现机制 1.1 什 ... -
【tomcat系统架构(二)】
2018-08-16 16:22 780四图带你了解Tomcat系统架构——让面试官颤抖Tomca ... -
【tomcat系统架构(一)】
2018-08-16 16:02 1511四图带你了解Tomcat系统架构——让面试官颤抖Tomca ... -
缓存总结(二)
2018-07-25 17:54 1357四种套路更新缓存 实时刷新缓存 分布式之数据库 ... -
常见性能优化策略的总结
2018-07-25 17:21 1371常见性能优化策略的总结
相关推荐
java代码-System.in.read()测试
本文实例讲述了C#中Forms.Timer、Timers.Timer、Threading.Timer的用法分析,分享给大家供大家参考。具体分析如下: ...是使用得比较多的Timer,Timer Start之后定时(按设定的Interval)调用挂接在Tick事
The parts may be read sequentially or in arbitrary order, depend- ing on the reader’s level of knowledge and specific areas of interest. A complete discussion of digital logic and microprocessor ...
2.4.1 Basic Operating System VSB Options ........................................................... 16 BSP-Specific Optimizations ........................................................................
z=(char)System.in.read(); System.in.skip(2); //忽略回车换行 } catch(IOException e){} } while(z=='y'); } public static double gets(Book a){ return a.sb; } public static double getx(Book ...
一本不错的C#书,希望对您有帮助,本书目录: ... Read This Book 1002 Index 1003 .NET Framework Class Library Documentation 1003 Search Engines 1004 Favorite Websites 1004 Summary 1004
编写字符界面的Java Application 接收用户输入的一个字符,并把该字符打印在屏幕上: ... ch=(char)System.in.read(); }catch(IOException e){}; System.out.println("You've entered character:"+ch); } }
Who Should Read This Book ..................................................................................................3 Prerequisite Knowledge.......................................................
Should you have any problems with overwriting or deleting the original file, remove attribute "read-only". 6. It is a must to run and execute file fix.reg, or else Nero applications could not be run....
Git is the source code control system preferred by modern development teams. Its decentralized architecture and lightning-fast branching let you concentrate on your code instead of tedious version ...
如果要使用read方法输入数据,应使用“System.in.read()”的形式。 在这个语句中,System是一个最终类,,不能用来产牛列象,它提供了 标准输入、标准输出和错误输出流;对外部定义的属性和环境变量的 访问;加载...
"Your detailed explanations are clear and backed-up with source code—and the numerous bits of humor make a dry subject very enjoyable to read." —J.D. Lindemann, network engineer, Adaptec, Inc. For ...
In complex web applications, the low-level details of your JavaScript code can obscure the workings of the system as a whole. As a coding style, functional programming (FP) promotes loosely coupled ...
Aligning Signals in Delta-Time . . . . . 201 Clock Multipliers . . 203 Asynchronous Reference Signals . . . 205 Random Generation of Reference Signal Parameters 206 Applying Reset . . . . 208 ...
tChar=(char)System.in.read(); }catch(IOException e){} } //递归函数调用求汉诺塔之解 public static void HanoiTower(int n,char a,char b,char c){ if(n==1){ System.out.print("Move disk from" +...
This is the best computer language book I've read.” – Robbin Carlson, Luthier and Enterprise Architect “I taught a CS2 Data Structures class in D with more success and student appreciation than ...
The demos should be run in the order in which they are listed in the supplied project group. Even if you have used previous versions of the Drag and Drop Component Suite it would be a good idea to ...