如何在 Java 中編寫常量名稱?
在編寫常量名稱時建議
- 使用大寫字母。
- 如果常量包含多個單詞,則應使用下劃線 (_) 分隔。
示例
public class ConstantsTest {
public static final int MIN_VALUE = 22;
public static final int MAX_VALUE = 222;
public static void main(String args[]) {
System.out.println("Value of the constant MIN_VALUE: "+MIN_VALUE);
System.out.println("Value of the constant MAX_VALUE: "+MAX_VALUE);
}
}
輸出
Value of the constant MIN_VALUE: 22 Value of the constant MAX_VALUE: 222
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP