我提出了一种方法,目的是删除问题清单。方法测试包含问题、答案、问题数量、点数。而且效果很好。
我得到以下错误:
无法访问的语句:System.out.println(“test \”+ testsindice - 1.getNomTest());
以下是代码:
public static int supprimerTest(Test[] tests, int nbrTests) {
int longueurTests = tests.length;
int indice = 0;
int noTest = 1;
int saisieNoTest = 0;
String nomTest;
System.out.println("***DELETE A TEST***\n");
if (nbrTests > 0) {
boolean fin = true;
do{
System.out.print("Please enter a number of the question to be deleted");
try {
indice = Clavier.lireInt();
if (indice < 1 || indice > nbrTests){
throw new IndexOutOfBoundsException();
System.out.println("The test \"" + tests[indice - 1].getNomTest());
tests[indice-1] =null;
nbrTests--;
fin = false;
}
}catch (Exception e) {
if (nbrTests < 1){
System.out.print("ERROR ! the number must be between 1 and " + nbrTests + "try again...");
}else {
System.out.println("ERROR ! the number must 1. ... Try again...");
}
}
}while (fin);
}else {
System.out.println("Il n'existe aucun test.");
System.out.print ("\nTPress <ENTRER> to continue ...");
Clavier.lireFinLigne();
}
return nbrTests;
}谢谢你的帮助。
发布于 2018-04-14 23:55:09
当您使用try语句时,如果检测到它,它会自动抛出异常。因此,只需取出抛出的异常行,那么您的代码就可以工作了。
https://stackoverflow.com/questions/49837170
复制相似问题