안녕하세요 저는 HomeTeam, AwayTeam, HomeScore, Awayscore로 4 개의 배열로 분할 된 축구 테이블에 대한 사용자 입력을 수집하는 프로그램을 만들어야하는 프로젝트를 수행하고 있습니다. 그런 다음 특정 형식으로 제공됩니다. Iv는이 기본 섹션을 완료했지만 사용자가 홈 팀과 원정 팀에 숫자를 입력하지 못하도록하고 또한 빈 공간으로 아무것도 입력하지 못하도록 예방할 필요가 있습니다.배열의 Java 유효성 검사
String[] hometeam = new String[100];
String[] awayteam = new String[100];
int[] homescore = new int[100];
int[] awayscore = new int[100];
int games = 0;
String amount = "";
boolean stop = true;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the amount of games you wish to list. Type stop to end program and show results");
amount = keyboard.nextLine();
int amountconvert = Integer.parseInt(amount);
String input = "";
if (amountconvert > 100) {
System.out.println("The maximum amount of games you can add is 100. Please try again");
return;
}
do {
System.out.println("Enter the HomeTeam:AwayTeam:HomeScore:AwayScore ");
input = keyboard.nextLine();
if (input.equalsIgnoreCase("stop")) {
break;
}
String[] inputindex = input.split(":");
if (Integer.parseInt(inputindex[2]) < 0 || Integer.parseInt(inputindex[3]) < 0) {
System.out.println("Errors found, Please format as shown");
} else if (inputindex.length == 4) {
hometeam[games] = inputindex[0];
awayteam[games] = inputindex[1];
homescore[games] = Integer.parseInt(inputindex[2]);
awayscore[games] = Integer.parseInt(inputindex[3]);
games++;
}
} while (games < amountconvert);
keyboard.close();
System.out.println("*******************************************************************");
for (int index = 0; index < games; index++) {
System.out.println(" " + hometeam[index] + " " + "[" + homescore[index] + "]" + " | " + awayteam[index]
+ " " + "[" + awayscore[index] + "]");
}
System.out.println("*******************************************************************");
저는 초보자이므로 도움을받을 수 있습니다. iv는 온라인으로 보았고 그것을 할 수있는 대부분의 방법은 try/catch와 while 루프이지만 그들이 필요로하는 위치와 루프를 만드는 방법을 파악할 수 없다.