import java.util.Scanner;
public class IterativeFactorial{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
System.out.println(" Enter number: ");
int num =sc.nextInt();
}
private static int IterativeFact(int num){
//System.out.println("Factorial of a number " +fact);
int fact = 1;
for(int i=num;i>0;i--){
fact = fact*i;
System.out.println("The factorial of a number is "+ fact);
}
return 1;
}
}
What is wrong with my print statement .
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
4 August 2021, 16:46
Does the task say to print whatever you are printing?
0
Guadalupe Gagnon
4 August 2021, 16:47
or are you asking why the IterativeFact() method doesn't print? That is because it isn't called in this code.
0
Dinesh
4 August 2021, 18:36
Sir , I am trying to call a private method inside the same class within main()
I am trying
get printed from
Tried again as follows please review
0
Guadalupe Gagnon
4 August 2021, 18:47
umm. What are the task instructions. This code is different than what you shared previously. The problems here:
Line 8-9: the method is static, you don't need an object to call a static method
line 9: the return value of the method is not saved in main
line 12: the variable 'fact' does not exist in main
line 24: the return value of the method is 1 no matter what number is entered
You may want to read up on how to implement and use methods in Java.
0
Dinesh
6 August 2021, 01:01
Your kind Mentoring helped me to resolve the issue . Thank you so much.
0