java的一些问题
1. 判断是否是奇数:
public static boolean isOdd(int i) { return i %2 != 0 ; }
2. System.out.println(2.0 - 1.1); 输出:0.89999999 99999999 (Double型的)
System.out.println(new BigDecimal("2.00").subtract(new BigDecimal("1.10"))); --输出 0.90 要加上引号,否则会有小数。
System.out.println(new BigDecimal("2.01").subtract(new BigDecimal("1.65"))); -- 输出 0.36
System.out.println(new BigDecimal(2.0).subtract(new BigDecimal(1.1))); -- 输出 0.899 99999999 99999111 82158029 98747676 61094665 52734375
System.out.printf("%.2f\n", 2.0-1.115); --输出:0.89
final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000;
final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
System.out.println(24 * 60 * 60 * 1000 * 1000); --- 输出: 500654080 , 当做了int型,导致越界。
System.out.println(24 * 60 * 60 * 1000 ); --- 输出: 86400000
System.out.println(MICROS_PER_DAY/MILLIS_PER_DAY); --- 输出 :5
对于长整型的计算,要加上L: System.out.println(24L * 60 * 60 * 1000 * 1000); --- 输出: 86400000 000
System.out.println("H" + "a"); 输出: Ha
System.out.println("H" + 'a'); Ha
System.out.println('H' + 'a'); 169
char[] numbers = {'1','2','3'};
System.out.println("a" + numbers); 输出:a[C@c3c749
Prints a String and then terminate the line. This method behaves as though it invokes and then print(String).println()
System.out.println(numbers); 输出:123
Prints an array of characters and then terminate the line. This method behaves as though it invokes and then print(char[]).println()
\u0022 是双引号的unicode编码。
System.out.println("a\u0022 + \u0022b ".length()); 相当于: System.out.println("a" + "b ".length()); , 输出 a2 。(b后面有一个空格)
System.out.println(Test.class.getName().replace(".","/")); 输出: com/Test
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".
System.out.println(Test.class.getName().replaceAll(".","/")); 输出:////////
System.out.println(Test.class.getName().replaceAll("\\.","/")); 输出:com/Test
Replaces each substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression
java.util.regex.Pattern.compile(regex).matcher(str).replaceAll(repl)
StringBuffer word = null;
word = new StringBuffer('P');
‘P’ 当做了int数。
Constructs a string buffer with no characters in it and the specified initial capacity.
- Parameters:
- capacity the initial capacity.
System.out.println(word); 输出换行
System.out.println(word.append("a")); 输出 a
int j = 0;
for(int i = 0; i < 100; i++){
j = j++;
System.out.println(j);
}
输出100 行 0 (j的值总是 0):
0
0
……
final int END=Integer.MAX_VALUE; //2147483647
final int START = END - 100;
int count = 0;
for(int i = START; i <= END; i++){
count++;
System.out.println(i); -- 死循环。 当 i 达到 2147483647 ,再增加会变成负数。
}
java的一些问题的更多相关文章
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题
背景起因: 记起以前的另一次也是关于内存的调优分享下 有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...
- Elasticsearch之java的基本操作一
摘要 接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...
- 论:开发者信仰之“天下IT是一家“(Java .NET篇)
比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- 死磕内存篇 --- JAVA进程和linux内存间的大小关系
运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- Java多线程基础学习(二)
9. 线程安全/共享变量——同步 当多个线程用到同一个变量时,在修改值时存在同时修改的可能性,而此时该变量只能被赋值一次.这就会导致出现“线程安全”问题,这个被多个线程共用的变量称之为“共享变量”. ...
- Java多线程基础学习(一)
1. 创建线程 1.1 通过构造函数:public Thread(Runnable target, String name){} 或:public Thread(Runnable target ...
- c#与java的区别
经常有人问这种问题,用了些时间java之后,发现这俩玩意除了一小部分壳子长的还有能稍微凑合上,基本上没什么相似之处,可以说也就是马甲层面上的相似吧,还是比较短的马甲... 一般C#多用于业务系统的开发 ...
随机推荐
- java 把json对象中转成map键值对
相关:Json对象与Json字符串的转化.JSON字符串与Java对象的转换 本文的目的是把json串转成map键值对存储,而且只存储叶节点的数据 比如json数据如下: {responseHeade ...
- Druid对比Vertica
怎么比较Druid和Vertica? Vertica 类似与之前介绍的ParAccel/Redshift(Druid-vs-Redshift). 不是实时注入数据: 提供SQL的全部语法支持 另外一个 ...
- 转:使用gradle 构建编译程序
https://rinvay.github.io/android/2015/04/09/Build-Android-with-Gradle/
- UIScreenAdaptive
using UnityEngine; namespace Com.Xyz.UI { [ExecuteInEditMode] [RequireComponent(typeof(UIRoot))] pub ...
- HTTP——代理协议 HTTP/1.1的CONNECT方法
我们平时使用HTTP协议无非就是GET.POST这些方法,但是HTTP的内容远不止那些.今天就来说说HTTP代理使用的CONNECT.这个不是在网页开发上用的,如果没兴趣就跳过吧. APACHE只是作 ...
- linux下统计程序/函数运行时间(转)
一. 使用time 命令 例如编译一个hello.c文件 #gcc hello.c -o hello 生成了hello可执行文件,此时统计该程序的运行时间便可以使用如下命令 #time ./hello ...
- GIT基本概念和用法总结【转】
在日常使用GIT过程中,经常会出错,比如无意间丢失了未提交的数据,回退版本时丢失了工作目录,等等.经过思考发现,所有这些错误都是因为对GIT中一些基本的概念模糊而导致,因为对一些基本概念不清晰,导致对 ...
- iOS 之UIBezierPath
代码地址如下:http://www.demodashi.com/demo/11602.html 在之前的文章中,由于用到过UIBezierPath这个类,所以这里就对这个类进行简单的记录一下,方便自己 ...
- Quartz的cron表达式 (spring定时器 crontab)
http://tangshuo.iteye.com/blog/184824 表达式位数最少六位,如每天凌晨一点启动:"0 0 1 * * ?" 顺序按 秒 分 时 日期 月份 ...
- python--web项目
zope:一个容器项目Plone:一个基于zope的工作流和内容管理项目trac:一个项目管理(任务指派.bug追踪项目,可以和subversion集成)moinmoin:一个强力的weiki系统