惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
Cloudbric
Cloudbric
I
InfoQ
V
V2EX
博客园_首页
The Register - Security
The Register - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Vercel News
Vercel News
Forbes - Security
Forbes - Security
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
D
DataBreaches.Net
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
B
Blog RSS Feed
A
About on SuperTechFans
N
News and Events Feed by Topic
Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
Attack and Defense Labs
Attack and Defense Labs
N
Netflix TechBlog - Medium
Spread Privacy
Spread Privacy
F
Full Disclosure
Recorded Future
Recorded Future
AWS News Blog
AWS News Blog
博客园 - 【当耐特】
The Cloudflare Blog
T
Threatpost
T
Tor Project blog
Google DeepMind News
Google DeepMind News
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
A
Arctic Wolf
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
Security Latest
Security Latest
The Last Watchdog
The Last Watchdog

博客园 - Rock Wang

Asp.Net Core Web Api基于cookie的安全验证 C#语言新特性(6.0-8.0) C#中Struct和Class的区别 iOS真机调试之免费预配(Free provisioning) iOS真机调试 Spring Boot学习笔记(1) Java学习笔记(9) Java学习笔记(7) Java学习笔记(6) Java学习笔记(5) Java学习笔记(4) Idea常用功能汇总 Java学习笔记(3) Java学习笔记(1) 如何开发NPM包 c#抓屏功能在DPI缩放后,截到的图片不完整的问题 支持续传功能的ASP.NET WEB API文件下载服务 ASP.NET MVC 阻止通过Url直接访问服务器上的静态文件 VS2013/VS2015/VS2017通过oschina托管代码
Java学习笔记(2)
Rock Wang · 2019-03-08 · via 博客园 - Rock Wang

int 和 booleam 不能直接转换,如下语法是不能通过的:

boolean b = true;
int i = (int) b;

int j = 1;
boolean a = (boolean) j;

对两个浮点数作相当比较时,经常不会得到想要的结果,如下:
double x=1.0 - 0.1 - 0.1  -0.1 - 0.1 - 0.1;
System.out.println(x == 0.5);

你可能期望打印 true, 但是会打印 false, 这跟浮点数的存储方式有关,实际上x不是0.5,而是0.5000000000000000001.

既然不能直接比较是否相等,可以比较二者差的绝对值是否小于某个非常小的极限值,可用如下公式来间接比较二者是否相等:
if |x - y| < ε, 其中的 ε 就是要采用的极限值,通常比较 double 类型的值时用1E-14, 比较 float 类型的值时用1E-7.
所以上面的比较可以改写为:

final double EPSILON = 1E-14;
double x=1.0 - 0.1 - 0.1 -0.1 -0.1 -0.1 -0.1;
if (Math.abs(x-0.5)<EPSLION){
  System.out.println("二者无限接近")
}

使用Math.random()产生一个0.0到1.0(不含)之间的浮点数

System.exit(int status); 用于终止程序,0表示正常退出,非0表示非