R
R
Rishat Sultanov2016-09-14 17:18:47
Java
Rishat Sultanov, 2016-09-14 17:18:47

How to send the user's input data to the method and return the result?

Good afternoon. I'm trying to make a mini factorial calculator.
The task of the program is to take data in the int type and run it through the factorial formula.
Something I don’t understand my mistake .. Push me on the right path.

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        System.out.print("Введите любое целое число: ");
        Scanner scan = new Scanner(System.in);
        int number = scan.nextInt();
        if (number < 0){
            System.out.println("Вам нужно указать положительное число");
        }
        else if(number == 0){
            System.out.println("По формуле ответ равен: 1");
        }
        else{
            Main.number(number);
            System.out.print(number);
        }
    }
    private static int number(int number) {
        while (number != 0) {
            return number * number(number - 1);
        }
    return number;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evhen, 2016-09-14
@EugeneP2

int factorial = Main.number(number);
            System.out.print(factorial);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question