以下代码的输出为320。
pdf[pdf.a>2]
有人可以向我解释一下吗? 先感谢您。它在什么基础上给予320。据我所知,它应该抛出异常。但是我要320。
答案 0 :(得分:1)
所有字符都有数字值,因此可以进行数学运算。
以下内容:
for (char c : "abcdefghijkln".toCharArray()) {
System.out.println("c = " + c + ", c has value of " + (int) c
+ ", c * 10 = " + (c * 10));
}
产生以下输出。
c = a, c has value of 97, c * 10 = 970
c = b, c has value of 98, c * 10 = 980
c = c, c has value of 99, c * 10 = 990
c = d, c has value of 100, c * 10 = 1000
c = e, c has value of 101, c * 10 = 1010
c = f, c has value of 102, c * 10 = 1020
c = g, c has value of 103, c * 10 = 1030
c = h, c has value of 104, c * 10 = 1040
c = i, c has value of 105, c * 10 = 1050
c = j, c has value of 106, c * 10 = 1060
c = k, c has value of 107, c * 10 = 1070
c = l, c has value of 108, c * 10 = 1080
c = n, c has value of 110, c * 10 = 1100