Hey Leute hier mein code:
also als Fehler krieg ich das:
AsciiShop.java:103: unreachable statement
if (cmd.equals("load")) {
^
1 error
2 Fragen:
1. Warum zeigt der aufs if?
2. Was soll da bitte falsch sein. cmd is definiert und die anderen funzen ja anscheindend auch, also wo liegt das Problem
gruss und dank euch schonmal für eure Antwort
Java:
import java.lang.*;
import java.util.*;
public class AsciiShop {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
AsciiImage ai = null;//Objekt von der Klasse AsciiImage, null == Leeres Objekt
String line;
//int elines = 0;
boolean z = true;
boolean load = false;
String strLoad = "";
String enof = "";//end of file
int width = 0;
int height = 0;
while (true) {
if (sc.hasNextLine()) {
line = sc.nextLine();
String[] opts = line.split(" ");//Option Linie gesplittet
String cmd = opts[0];//command von opts
if (z) {
if (cmd.equals("create")) {
//pruefen ob genau 2 opts uebergeben wurden exkl cmd.
if(!(opts.length == 3)) {
System.out.println("INPUT MISMATCH");
break;
}
if (checkInt(Integer.parseInt(opts[1]))) {//überprüfen von ops 1, Integer.parseInt = einlesen von In werten
width = Integer.parseInt(opts[1]);
} else {
System.out.println("INPUT MISMATCH");
break;
}
if (checkInt(Integer.parseInt(opts[2]))) {
height = Integer.parseInt(opts[2]);
} else {
System.out.println("INPUT MISMATCH");
break;
}
//macht das Image in der richtigen Groesse
ai = new AsciiImage(width, height);
z = false;
continue;
} else {
//kein create
System.out.println("INPUT MISMATCH");
break;
}
}
if (load) {
if (line.equals(enof)) {
load = false;
if (!ai.load(strLoad)) {
System.out.println("INPUT MISMATCH");
break;
}
continue;
}
if (line.length() == ai.getWidth()) {
strLoad += line;
continue;
} else {
System.out.println("INPUT MISMATCH");
break;
}
}
if (cmd.equals("clear")) {
ai.clear();
continue;
} else if (cmd.equals("line")) {
if(!(checkInt2(Integer.parseInt(opts[1])) || checkInt2(Integer.parseInt(opts[2])) || checkInt2(Integer.parseInt(opts[3])) || checkInt2(Integer.parseInt(opts[4])) )) {
System.out.println("INPUT MISMATCH");
break;
}
ai.drawLine(Integer.parseInt(opts[1]),Integer.parseInt(opts[2]),Integer.parseInt(opts[3]),Integer.parseInt(opts[4]),opts[5].charAt(0));
continue;
if (cmd.equals("load")) {
strLoad="";
enof = opts[1];
load = true;
continue;
} else if (cmd.equals("print")) {
System.out.print(ai.toString());
continue;
} else if (cmd.equals("replace")) {
ai.replace(opts[1].charAt(0), opts[2].charAt(0));
continue;
} else if (cmd.equals("transpose")) {
ai.transpose();
continue;
} else if (cmd.equals("")) {
break;
} else {
System.out.println("UNKNOWN COMMAND");
break;
}
} else {
break;
}
//END
}
}
}
private static boolean checkInt(int z) {
if (z > 0) {
String s = String.valueOf(z);
for (int i = 0; i < s.length(); i++) {
if (!Character.isDigit(s.charAt(i))) {//
return false;
}
}
return true;
} else {
return false;
}
}
private static boolean checkInt2(int z) {//dito
if (z >= 0) {
String s = String.valueOf(z);
for (int i = 0; i < s.length(); i++) {
if (!Character.isDigit(s.charAt(i))) {
return false;
}
}
return true;
} else {
return false;
}
}
}
also als Fehler krieg ich das:
AsciiShop.java:103: unreachable statement
if (cmd.equals("load")) {
^
1 error
2 Fragen:
1. Warum zeigt der aufs if?
2. Was soll da bitte falsch sein. cmd is definiert und die anderen funzen ja anscheindend auch, also wo liegt das Problem
gruss und dank euch schonmal für eure Antwort