leejunki159
Messages postés4Date d'inscriptionmardi 21 avril 2015StatutMembreDernière intervention13 mai 2015
-
Modifié par Whismeril le 13/05/2015 à 23:33
KX
Messages postés16734Date d'inscriptionsamedi 31 mai 2008StatutModérateurDernière intervention24 avril 2024
-
14 mai 2015 à 09:38
Bonjour,
j'ai un problème dans mon code java lorsque j'entre n=170 le résultât s'affiche mais si j'entre n=171 il me donne "infinity " au lieu d'une résultat numérique pouvez vous m'aider svp
package loi.normale;
import java.math.BigInteger;
import java.util.Scanner;
public class somme {
public static double factorielle(double x) {
double i;
double result=1;
if(x >= 1) {
for(i=x;i>1;i--) {
result = result*i;
}
return result;
}
else if(x == 0) return 1;
return 0;
}
public static double compter_combinaisons(double k,double n) {
double z = n-k;
return factorielle(n)/(factorielle(k)*factorielle(z));
}
public static double som(float a,float b,int n,float p ) {
double s = 0;
for(float i= a;i<=b;i++){
s=s+compter_combinaisons(i,n)*Math.pow(p, i)*Math.pow((1-p), (n-i));
}
return s;
}
public static void main(String args[] ) {
int i;
int n;
float b,a;
double s;
Scanner sc=new Scanner(System.in);
System.out.println("a=");
a=sc.nextFloat();
System.out.println("b=");
b=sc.nextFloat();
System.out.println("n=");
n=sc.nextInt();
s= som(a,b,n, (float) 0.5);
System.out.println("binomiale :"+s);
}
}