URI Problem (Simple Factorial) 1153 Solution in Java

Problem Solving, URI

URI Problem (Simple Factorial) 1153:
Simple Factorial is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 21, 2016
 * @Time : 10:08:20 PM
 */
public class Uri1153 {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String value = br.readLine().trim();
        int x = Integer.valueOf(value);
        if (x > 0 && x < 13) {
            bw.write(getFactorial(x)+"\n");
            bw.flush();
        }
        bw.close();
        br.close();
    }

    private static int getFactorial(int x) {
        if (x == 1) {
            return 1;
        } else {
            return x * getFactorial(x - 1);
        }
    }
}

0 Comments

You may find interest following article

Complete Guide: Create Laravel Project in Docker Without Local Dependencies

Create Laravel Project Through Docker — No Need to Install PHP, MySQL, or Apache on Your Local Machine In this tutorial, I’ll show you how to create and run a full Laravel project using Docker containers. That means you won’t have to install PHP, MySQL, or Apache locally on your computer. By the end of this guide, you’ll have a fully functional Laravel development...