Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package methodsAndFunctions;
- import java.io.PrintStream;
- import java.util.Scanner;
- class Pizza {
- // Name : Christopher Esterhuyse
- // Assignment : methodsAndFunctions
- // Date : 16-September 2014
- PrintStream out;
- Pizza() {
- out = new PrintStream(System.out);
- }
- void start() {
- Scanner in = new Scanner(System.in);
- int MARIO_POSSIBLE = 10,
- MARIO_NUMBER = 3,
- LUIGI_POSSIBLE = 9,
- LUIGI_NUMBER = 4;
- if(possibilities(MARIO_POSSIBLE, MARIO_NUMBER) > possibilities(LUIGI_POSSIBLE, LUIGI_NUMBER)){
- out.printf("Mario wins the bet!");
- }else{
- if(possibilities(MARIO_POSSIBLE, MARIO_NUMBER) < possibilities(LUIGI_POSSIBLE, LUIGI_NUMBER)){
- out.printf("Luigi wins the bet!");
- }else{
- out.printf("Both brothers are tied!");
- }
- }
- in.close();
- }
- int possibilities(int possibleToppings, int numberToppings){
- int result = factorial(possibleToppings)/(factorial(numberToppings)*factorial(possibleToppings-numberToppings)); //n!/(k!(n-k)!)
- return result;
- }
- int factorial(int n){
- int result = 1;
- for(int i=1; i<n; i++){
- result *= i;
- }
- return result;
- }
- public static void main (String[] argv) {
- new Pizza().start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement