+ 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

29th Apr 2017, 12:31 PM
Saikat Mukherjee
Saikat Mukherjee - avatar
6 Answers
+ 8
Handle exceptions. I entered -5 , Ans =1 I entered an alphabet ,error
29th Apr 2017, 12:44 PM
Meharban Singh
Meharban Singh - avatar
+ 11
Try to modify the indentations so that your code looks neat. And, check this out. https://code.sololearn.com/cetfyzhulHuV/?ref=app
29th Apr 2017, 2:03 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 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.
29th Apr 2017, 2:40 PM
Meharban Singh
Meharban Singh - avatar
+ 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
29th Apr 2017, 2:45 PM
Meharban Singh
Meharban Singh - avatar
+ 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!!"); } } }
29th Apr 2017, 12:53 PM
Saikat Mukherjee
Saikat Mukherjee - avatar
17th Nov 2017, 9:40 AM
#RahulVerma
#RahulVerma - avatar