+ 1
How to do factorial by using one for-loop?
Check this out.If you have any suggestion then tell me.âșâșđ https://code.sololearn.com/c35ADHo2ZJjX/?ref=app
6 Answers
+ 8
Handle exceptions.
I entered -5 , Ans =1
I entered an alphabet ,error
+ 11
Try to modify the indentations so that your code looks neat. And, check this out.
https://code.sololearn.com/cetfyzhulHuV/?ref=app
+ 7
I agree with @Krishna Sir ,also try adding comments. Like this :-
https://code.sololearn.com/c56Bnye5KD1E/?ref=app
TRICK :- In eclipse, open your code. Ctrl + A to select all. Ctrl + i to align things properly.
+ 7
Also @Krishna Sir, please tell if my last 2 methods can be converged to single. I feel like its possible,but dont know how. Thanks
https://code.sololearn.com/c56Bnye5KD1E/?ref=app
+ 2
@Meharban Singh Thanks for the suggestion.I am going to repost this.Check this out.đđđ
package Java1; import java.util.*;
public class Vool2 {
public static void main(String[] args)
{ int N=1;
Scanner input=new Scanner(System.in);
try { int xo=0;
do { System.out.println("Now enter a value to do factorial" );
int u=input.nextInt();
for(int i=u;i>0;i--)
{
N=i*N;
}
System.out.println(N); System.out.println("If you want to continue this process then please enter 1 otherwise 0"); xo=input.nextInt();
N=1;
}while(xo!=0);} catch(Exception e)
{ System.out.println("Exception is created\nHave to terminate the program!!"); } } }