注册 登录
编程论坛 JAVA论坛

学数据初始化程序老是出错。需要修改哪里》?以附代码。

Eeiou 发布于 2015-12-08 14:53, 2229 次点击
public class ArrayDefaultValue {                                       
    public static void main(String args[])
    {
        byte[]byteArray=new byte[1];
        char[]charArray=new char[1];
        int[]intArray=new int[1];
        long []longArray= new long[1];
        float []floatArray=new float[1];
        double []doubleArray=new double[1];
        String[]stringArray=new String[1];
        System.out.println("byte+"byteArray[0]);
        System.out.println("char+"charArray[0]);
        System.out.println("int+"intArray[0]);
        System.out.println("long+"longArray[0]);
        System.out.println("float+"floatArray[0]);
        System.out.println("double+"doubleArray[0]);
        System.out.println("string+"stringArray[0]);
    }   

}
运行结果。这是什么意思?
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    The type of the expression must be an array type but it resolved to String
    Syntax error on token "byteArray", delete this token
    The type of the expression must be an array type but it resolved to String
    Syntax error on token "charArray", delete this token
    The type of the expression must be an array type but it resolved to String
    Syntax error on token "intArray", delete this token
    The type of the expression must be an array type but it resolved to String
    Syntax error on token "longArray", delete this token
    The type of the expression must be an array type but it resolved to String
    Syntax error on token "floatArray", delete this token
    The type of the expression must be an array type but it resolved to String
    Syntax error on token "doubleArray", delete this token
    The type of the expression must be an array type but it resolved to String
    Syntax error on token "stringArray", delete this token

    at ArrayDefaultValue.main(ArrayDefaultValue.java:12)
2 回复
#2
紫月一殇雪2015-12-08 17:44
你用了关键字。。。。。
#3
紫月一殇雪2015-12-08 17:46
并不是 ,你是把+写在引号里面了,如果你要拼接字符串,你需要写成  System.out.println("ss"+byteArray[0]);
注意我的加号在引号外面!!!
1