THE CODERZ TECH LOUNGE
Often in classrooms we are taught that the main function is the ‘main’ function in a program! But it actually is not so. That is actually the default behavior of the compiler. The compiler has a predefined set of rules according to which :: 1. The main() function has a default priority of 0, which is [...]
A blank frame window :: import javax.swing.*; public class swingstart { public static void main(String[] args) { SimpleFrame frame=new SimpleFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } class SimpleFrame extends JFrame { public SimpleFrame() { setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT); } static final int DEFAULT_WIDTH=400; static final int [...]
And then there is theĀ very famous python. Amazingly the factorial program in this case becomes even simpler. It is just a normal factorial code seemingly working fine for abnormally large integers as well! fact=1 x=input("Enter the no :") for x in range(1,x+1): fact*=x print "Factorial :" print fact
In java though, the factorial can be easily implemented in SE6 using the bigInteger class. The logic is the same as for finding factorials. The code goes as follows :: import java.math.BigInteger; import java.lang.*; import java.util.Scanner; class largenumber { public static void main(String args[]) { Scanner in=new Scanner(System.in); System.out.println("Enter a number for factorial"); int num=in.nextInt(); BigInteger fact=BigInteger.valueOf(1); for(int i=2;i<=num;i++) { fact=fact.multiply(BigInteger.valueOf(i)); } System.out.println("Factorial "+num+" is ::\n\t"+fact); } }
A lot of time we have tried to work with large numbers in c and end up getting a round off or a zero. This is just on of the many ways to work with large numbers without aly external library support. We have implemented our code and storage with the help of the derived [...]