public class Lance { public static int moyenne(String[] liste) throws ExceptionRien { int i, somme = 0, nbEntiers = 0; for (String chaine : liste) { try { somme += Integer.parseInt(chaine); nbEntiers++; } catch (NumberFormatException e) { System.out.println(chaine + " n'est pas entier"); } } if (nbEntiers == 0) throw new ExceptionRien(liste.length); return somme/nbEntiers; } } class EssaiLance { public static void main(String[] arg){ try { System.out.println("La moyenne est : " + Lance.moyenne(arg)); } catch (ExceptionRien e) { e.printStackTrace(); } } } /*Pour : java ExceptionThrows ha 15.5 ha n'est pas entier 15.5 n'est pas entier ExceptionRien : aucune des 2 chaines n'est valide at Lance.moyenne(Lance.java:15) at EssaiLance.main(Lance.java:23) */