有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java标识符预期问题

我似乎找不到这里的错误。显然,所有常量的“final”后面都应该有一个标识符。有人能帮忙吗

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Letter
{
    private static final int 30G_PRICE = 40; 
    private static final int 50G_PRICE = 55;  
    private static final int 100G_PRICE = 70; 
    private static final int ADDITIONAL_50G_PRICE = 25;
    public static void main (String[] args) throws IOException
    {
    BufferedReader console = 
        new BufferedReader(new InputStreamReader(System.in));
    }   
}

共 (2) 个答案

  1. # 1 楼答案

    不能用数字启动变量(或任何其他标识符)名称

    From the tutorials

    Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_".

  2. # 2 楼答案

    变量名(或任何其他标识符的名称)不能以数字开头。试试这个:

    导入java。木卫一。缓冲读取器; 导入java。木卫一。输入流阅读器; 导入java。木卫一。IOException

    public class Letter
    {
        private static final int PRICE_30G = 40; 
        private static final int PRICE_50G = 55;  
        private static final int PRICE_100G = 70; 
        private static final int ADDITIONAL_50G_PRICE = 25;
        public static void main (String[] args) throws IOException
        {
        BufferedReader console = 
            new BufferedReader(new InputStreamReader(System.in));
        }   
    }
    

    允许将数字放在标识符中的任何其他位置