1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| public class tprec {
/**
* @param args
*/
public static int fact(int n) throws ExceptionNegg, ExceptionGrandd {
{
if (n==0) return 1;
else return n*fact(n-1);
}
}
public static int n ;
public static void main(String[] args) throws ExceptionGrandd, ExceptionNegg {
// TODO Auto-generated method stub
try {
int i = 0;
n = Integer.parseInt(args[i]);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("veuillez faire la saisie erreur :"+e.getMessage()+"\n");
}
catch(NumberFormatException e2){
System.out.println("vous avez saisi un caractère erroné veuillez saisir un entier\n");
try{
if(n<0) throw new ExceptionNegg();
{ System.out.println("factorielle de "+n+" : "+fact(n));}
}
catch(ExceptionNegg e3) {
System.out.println("L'entier saisi est négatif\n");
try {
if(n>99999) throw new ExceptionGrandd();
{ System.out.println("factorielle de "+n+" : "+fact(n));}
}
catch( ExceptionGrandd e4) {
System.out.println("L'entier saisi est très grand\n");
}
}
}
}
} |
Partager