当我尝试编译此代码时,出现此错误:
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] 删除。
我来说两句