Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 19/46/2018 at 18:46:43
- * FactorialDivision.java created by Tsvetelin
- */
- package Methods_Excerices;
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.util.Scanner;
- /**
- * @author Tsvetelin
- *
- */
- public class FactorialDivision
- {
- /**
- * @param args
- */
- public static void main ( String [] args )
- {
- Scanner in = new Scanner( System.in );
- int a = Integer.parseInt( in.nextLine() );
- int b = Integer.parseInt( in.nextLine() );
- boolean positiveA = a>0; a = Math.abs( a );
- boolean positiveB = b>0; b = Math.abs( b );
- BigInteger factA = positiveA
- ? factorial( new BigInteger( a + "" ) )
- : BigInteger.ZERO.subtract( factorial( new BigInteger( a + "" ) ) );
- BigInteger factB = positiveB
- ? factorial( new BigInteger( b + "" ) )
- : BigInteger.ZERO.subtract( factorial( new BigInteger( b + "" ) ) );
- System.out.printf( "%.2f", divide( factA, factB ) );
- }
- /**
- * @param a
- * @param b
- * @return
- */
- private static BigDecimal divide ( BigInteger a , BigInteger b )
- {
- return new BigDecimal( a.divide( b ) );
- }
- /**
- * @param a
- * @return
- */
- private static BigInteger factorial ( BigInteger a )
- {
- if(a.compareTo( BigInteger.ZERO ) == 0) return BigInteger.ONE;
- else return a.multiply( factorial( a.subtract( BigInteger.ONE ) ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement