- Start main body with starting curly braces and declare two variables lets say a and b.
- Take input inside a using easyin method.
- choose a proper name of method lets say factii and call the method and assign value of it to b. like b=factii(a);
- When compiler will read the caller it will find the method factii from the code and will reach there.
- write output statement that prints the final value. like ..............println(" "+b);
- Write ending curly braces.
- Make a method have name factii and one parametre of int type and should have int return type like public static int factii(int x). This x will take the value of a from the caller in the 3rd point.
- Initialize a variable lets say c =1
- Write starting curly braces and then Start a loop from 1 to less then x and increment it by 1.
- Write starting curly braces of this loop.
- Inside loop write a statement like c=c*x;
- Write ending curly braces of method factii.
- Write return statement like return c; so it will return the final value of c to the b from the caller and then on the fourth line value of b will be showed.
This blog is made for my dear class fellows to provide algorithms of different problem statements of JAVA.
Monday, 30 January 2012
Computing factorial using method
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment