[Homework]Packet switching versus circuit switching


[Homework]Packet switching versus circuit switching_第1张图片


Following is the key in detail, i just implemented it in java:


import java.text.DecimalFormat;

public class test {
	public static void main(String[] args) {
		double sumP = 0.0;
		for (int i = 11; i <= 35; i++) {
			sumP += getCombination(i, 35)*Math.pow(0.1,i)*Math.pow(0.9, 35-i);
		}
		DecimalFormat df = new DecimalFormat("#.0000000");
		String fP = df.format(sumP);
		System.out.println(fP);
		
	}
	
	public static double getCombination(int r, int n){
		return doFactorial(n)/(doFactorial(r)*doFactorial(n-r));
	}
	
	public static double doFactorial(int n){
		if(n<0){
			return -1;
		}
		else if(n==0){
			return 1;
		}
		else if(n==1){
			return 1;
		}
		else{
			return n*doFactorial(n-1);
		}

	}

}

the result is 0.0004243

你可能感兴趣的:(未分类)