Java方法名称错误

卢卡传奇

当我尝试编译此代码时,出现此错误:

dn09.java:38: error: illegal start of expression
                public Tip[] preberi (Scanner sc) {
                ^ dn09.java:38: error: ';' expected
                public Tip[] preberi (Scanner sc) {
                                    ^ dn09.java:38: error: ';' expected
                public Tip[] preberi (Scanner sc) {
                                                ^ 3 errors

[Napaka | process.javac]: Object reference not set to an instance of an object.

这是问题中的代码行:

public Tip[] preberi(Scanner sc) {
            Tip[] tipi = new tipi[d];
            for (int i = 0; i < tipi.length; i++) {
                String tip = sc.next();
                    switch (tip) {
                        case "prim":
                            tipi[i] = new Prim(sc.nextInt());
                            break;
                        case "arr":
                            tipi[i] = new Arr(sc.nextInt(), sc.nextInt());
                            break;
                        case "ostruct":
                            break;
                        case "pstruct":
                            break;
                    }
            }
            return tipi;
        }

我已经Scanner在该main()方法中声明了它,它已导入并包含所有内容。

正如您中的一些人问的那样,这是我的整个代码(它根本没有处于工作状态,因为您还将看到我是一个初学者,所以它的美感很简单。

public class dn09 {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int b = sc.nextInt();
    int d = sc.nextInt();
    Tip[] tipi = preberi(sc);
    int u = sc.nextInt();
    int[] ukazi = new int[u];
    for (int i = 0; i < u; i++) {
        ukazi[i] = sc.nextInt(); //if you know a better way to store 2 numbers where i could then
                                 //use the numbers separately that would be super helpfull as id        
    }                            //need it for 2 switch statements which im currenty trying to 
    for (int i = 0; i < u; i++) {//fit into 1.
        switch(ukazi[i]) {
            case 11:
                break;
            case 12:
                break;
            case 13:
                break;
            case 21:
                break;
            case 22:
                break;
            case 23:
                break;
            case 31:
                break;
            case 32:
                break;
            case 33:
                break;
        }
    }


    public Tip[] preberi(Scanner sc) {
        Tip[] tipi = new tipi[d];
        for (int i = 0; i < tipi.length; i++) {
            String tip = sc.next();
                switch (tip) {
                    case "prim":
                        tipi[i] = new Prim(sc.nextInt());
                        break;
                    case "arr":
                        tipi[i] = new Arr(sc.nextInt(), sc.nextInt());
                        break;
                    case "ostruct":
                        break;
                    case "pstruct":
                        break;
                }
        }
        return tipi;
    }
}

private static class Prim extends dn09 {
    protected int v;
    public static Prim (int v) {
        this.v = v;
    }
}

private static class Arr extends dn09 {
    protected int n;
    protected int t;
    public static Arr (int n, int t) {
        this.t = t;
        this.n = n;
    }
}

}

您的main()方法需要关闭,}您只需要关闭循环并进行切换即可。

您还需要static从内部类的构造函数(Prim(int)Arr(int,int))中删除两者}末端有一个悬挂物,也许您想移除一个关闭的东西?

如果使用IDE并自动缩进代码,则这些问题很快就会显现出来。

public class dn09 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int b = sc.nextInt();
        int d = sc.nextInt();
        Tip[] tipi = preberi(sc);
        int u = sc.nextInt();
        int[] ukazi = new int[u];
        for (int i = 0; i < u; i++) {
            ukazi[i] = sc.nextInt(); //if you know a better way to store 2 numbers where i could then
            //use the numbers separately that would be super helpfull as id
        }                            //need it for 2 switch statements which im currenty trying to
        for (int i = 0; i < u; i++) {//fit into 1.
            switch(ukazi[i]) {
                case 11:
                    break;
...
            }
        }
    }

    public Tip[] preberi(Scanner sc) {
        Tip[] tipi = new tipi[d];
        for (int i = 0; i < tipi.length; i++) {
            String tip = sc.next();
            switch (tip) {
                case "prim":
                    liki[i] = new Prim(sc.nextInt());
                    break;
...
            }
        }
        return tipi;
    }

    private static class Prim extends dn09 {
        protected int v;
        public Prim (int v) {
            this.v = v;
        }
    }

    private static class Arr extends dn09 {
        protected int n;
        protected int t;
        public Arr (int n, int t) {
            this.t = t;
            this.n = n;
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

TimerCallBack方法名称(错误除外)

来自分类Dev

方法名称预期错误-C#

来自分类Dev

Java方法名称分析器

来自分类Dev

什么是错误“在方法名称中发现无效字符。HTTP方法名称必须为令牌”

来自分类Dev

方法错误:方法名称未定义

来自分类Dev

动态方法名称

来自分类Dev

单击EventHandler:预期方法名称和其他错误

来自分类Dev

期望的方法名称-使用lambda表达式错误?

来自分类Dev

Java,通过反射进行记录的方法名称

来自分类Dev

Java 8:重复的方法名称和签名lambda

来自分类Dev

允许使用的非凡的Java方法名称还有哪些?

来自分类Dev

如何在Java中动态传递方法名称

来自分类Dev

Java获取编译时安全的方法名称

来自分类Dev

在Java过滤器中获取方法名称

来自分类Dev

如何在Java运行时更改方法名称?

来自分类Dev

允许使用的非凡的Java方法名称还有哪些?

来自分类Dev

在Java过滤器中获取方法名称

来自分类Dev

如何在java循环中动态更改方法名称

来自分类Dev

Java 接口仅定义方法名称(即变量参数)

来自分类Dev

Rails动态方法名称

来自分类Dev

比“ isThis()”更好的方法名称

来自分类Dev

方法名称不是函数

来自分类Dev

登录-获取方法名称

来自分类Dev

Swift中的方法名称

来自分类Dev

TypeScript中的方法名称

来自分类Dev

AOSP方法名称的结尾

来自分类Dev

比“ isThis()”更好的方法名称

来自分类Dev

动态调用方法名称?

来自分类Dev

Rails动态方法名称