Skip to main content

Posts

Showing posts from 2017

Find Factorial Of N (N- As big as you can think)

YouTube channel:  https://www.youtube.com/channel/UC6U6yckyKymb36I0ytwrnXw Want to find factorial of N without using built-in BIG Number classes available in Java. Here you go! Achieve it with the simple idea of Linked Lists in Java. File: BIGNumbers.java --------------------------------------- //Data class to represent BIG number each data node containing digits //This helps handle big numbers as List can grow. //int and long types support limited digits only (Range: 2^32 , 2^64 ) //A better way to handle big numbers is to use an array of bytes / list of bytes class Data{ byte value;//Byte type is sufficient to save value 0~9 Data nextData; Data(byte value){ this.value = value; this.nextData=null; } } public class BIGNumbers{ byte zero=0; byte carryForward=0; byte ten=10; Data result=null; Data resultData=null; BIGNumbers(){} //To find list size int listSize(Data list){ int length=0; while(list!=null){ length++; list=list.n