1. /**
    2. * @author LeapingQuantum
    3. */
    4. public class Const {
    5. public static void main(String[] args) {
    6. // 字符串常量
    7. System.out.println("String constant 1");
    8. System.out.println("");
    9. System.out.println("String constant 2");
    10. // 整数常量
    11. System.out.println(30);
    12. System.out.println(-500);
    13. // 浮点数常量
    14. System.out.println(3.14);
    15. System.out.println(-2.5);
    16. // 字符常量
    17. System.out.println('a');
    18. System.out.println('0');
    19. // 布尔常量
    20. System.out.println(true);
    21. System.out.println(false);
    22. // 空常量(不能直接用来打印输出)
    23. // System.out.println(null);
    24. }
    25. }

    运行结果:

    1. String constant 1
    2. String constant 2
    3. 30
    4. -500
    5. 3.14
    6. -2.5
    7. a
    8. 0
    9. true
    10. false