代码:
//: operators/Literals.java
import static net.mindview.util.Print.*;public class Literals {
  public static void main(String[] args) {
    int i1 = 0x2f; // Hexadecimal (lowercase)
    print("i1: " + Integer.toBinaryString(i1));
    int i2 = 0X2F; // Hexadecimal (uppercase)
    print("i2: " + Integer.toBinaryString(i2));
    int i3 = 0177; // Octal (leading zero)
    print("i3: " + Integer.toBinaryString(i3));
    char c = 0xffff; // max char hex value
    print("c: " + Integer.toBinaryString(c));
    byte b = 0x7f; // max byte hex value
    print("b: " + Integer.toBinaryString(b));
    short s = 0x7fff; // max short hex value
    print("s: " + Integer.toBinaryString(s));
    long n1 = 200L; // long suffix
    long n2 = 200l; // long suffix (but can be confusing)
    long n3 = 200;
    float f1 = 1;
    float f2 = 1F; // float suffix
    float f3 = 1f; // float suffix
    double d1 = 1d; // double suffix
    double d2 = 1D; // double suffix
    // (Hex and Octal also work with long)
  }
} /* Output:
i1: 101111
i2: 101111
i3: 1111111
c: 1111111111111111
b: 1111111
s: 111111111111111
*///:~问题:long n1 = 200L; // long suffix
long n2 = 200l; // long suffix (but can be confusing)
long n3 = 200;什么意思?三条语句都一样吗?

解决方案 »

  1.   

    第2个看不懂
    第一行表示把n1定义为long型变量200L
    第三行表示,把一个int类型的量赋值给long,因为long的范围比int大 所以这样是可以的
    第2个是小写的L么?
      

  2.   

    long型变量200L  是意思是200.0000000吗?
      

  3.   

    n1和n2是一样的,不过一般不赞成n2 的写法,容易混淆
    n3定义的是int类型然后隐式转换成long类型