我对Java还是很陌生,如果我的问题太简单了,我感到抱歉,但是由于我找不到switch语句从不执行的原因,因此我仍然受阻。 这是代码:
static void findSpot(String[][] parking) {
boolean control = false, repeat;
System.out.println("Insert o Floor : Spot");
Scanner s = new Scanner(System.in);
String[] floorSpot = s.nextLine().split(":");
int floor, spot;
floor = Integer.parseInt(floorSpot[0]);
spot = Integer.parseInt(floorSpot[1]);
if (floor >= parking.length) {
System.out.println("Invalid floor number!");
}
System.out.println("Insert registry: 00-00-AA 00-AA-00");
String registry = s.nextLine();
repeat = validateRegistry(registry);
if (!repeat) {
System.out.println("Invalide format.");
}
}
答案 0 :(得分:-1)
对不起,但Stack over流上的定义不允许我在此处发布整个代码,并简要解释错误:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.System.out;
public class ex17 {
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int x=args.length;//
String[][] parking=new String[x][];
setPositions(parking,args);
boolean exit = false;
while (!exit) {
char choice;
out.println("\nE- Entrance vehicle");
out.println("T- Terminate");
out.print("Option -> ");
choice = in.next().toLowerCase().charAt(0);
switch (choice) {
case 'e':
findSpot(parking);
break;
case 't':
exit=quitProgram();
break;
default:
out.println(Invalid\n".toUpperCase());
break;
}
static void findSpot(String[][] parking) {
boolean control = false, repeat;
System.out.println("Insert o Floor : Spot");
Scanner s = new Scanner(System.in);
String[] floorSpot = s.nextLine().split(":");
int floor, spot;
floor = Integer.parseInt(floorSpot[0]);
spot = Integer.parseInt(floorSpot[1]);
if (floor >= parking.length) {
System.out.println("Invalid floor number!");
}
System.out.println("Insert registry: 00-00-AA 00-AA-00");
String registry = s.nextLine();
repeat = validateRegistry(registry);
if (!repeat) {
System.out.println("Invalide format.");
}
}