15,916,318 members
See more:
How do I print the Scanner the output of the functions above, and I am a beginner in Java

What I have tried:

```    import java.util.Scanner;

public class factorial {

// Factorial number  Non Recursive Use a for loop
public static int factorial(int num) {
int n=1;
if(num==0)
return 1;
for(int i=1; i<=num; i++) {
n=n*i;
}
return n;
}

// With Recursive: a function is calling itself
public static int r(int numb) {
if(numb==0)
return 1;

else
return (numb * r (numb-1));

}

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter factorial Number: ");
System.out.println("Factorial Recursive is: "+n);
System.out.println("Factorial Number Non-Recursive is: "+numb);

}  // End of main

}  // End of class
```
Java
```
```
Posted
Updated 27-Mar-21 9:44am

## Solution 1

Look at your `main` method: You read the number to calculate the factorial of before you prompt the user to enter it!

Then printing your answers is simple - you just have to call the method you wrote and print the result.

If you define a method then calling it is easy:
Java
```public static void main(String[] args) {
System.out.println(" 3 + 6 = " + Add(3, 6));
}
private static int Add(int x, int y) {
return x + y;
}
```