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 <code>print(String)
and then <code>println()
.
System.out.println(numbers); 输出:123
Prints an array of characters and then terminate the line. This method behaves as though it invokes <code>print(char[])
and then <code>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中遇到的问题总结的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Dreamweaver Mac版
视觉化网页开发工具

记事本++7.3.1
好用且免费的代码编辑器

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。