Товарищи!
Прошу помощи, не понимаю как вывести строковый результат((
Дайте подсказку
/*
Факториал
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
reader.close();
if (input > 150) { //Только так смог сделать условие >150
System.out.println("Ввели больше 150");} //Иначе ошибки Стринг
else
System.out.println(factorial(input));
}
public static BigInteger factorial(int n) { //Вычитал про BigInteger
if (n < 0) return BigInteger.ZERO; //Так смог вывести 0
BigInteger result = BigInteger.ONE; //Начинает с 1
if (n <= 150) {
for (int i = 1; i <= n; i++) {
result = result.multiply(BigInteger.valueOf(i));
} //перемножает себя на i
} return result;
}
}package com.javarush.task.task15.task1531;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
/*
Факториал
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
reader.close();
if (input > 150) {
System.out.println("Ввели больше 150");}
else
System.out.println(factorial(input));
}
public static BigInteger factorial(int n) {
if (n < 0) return BigInteger.ZERO;
BigInteger result = BigInteger.ONE;
if (n <= 150) {
for (int i = 1; i <= n; i++) {
result = result.multiply(BigInteger.valueOf(i));
}
} return result;
}
}