Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Having problem with factorial

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having problem with factorial

    Hi guys, I don't understand what i'm doing wrong here. I'm supposed to print factorial of the inserted integer.

    1. first to ask the number (for example 3)
    2. count its factorial and print it on the screen (6) 1*2*3 = 6

    Here's my code

    import java.io.*;

    public class factorial {

    public static void main(String[] args) throws IOException {

    int i, num, factori;
    factori = num;

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    for(num<0; num=<factori) {
    System.out.print("Insert number:"); {
    num = Integer.parseInt(in.readLine());
    System.out.println("The factorial of" +num+ "is" +factori);


    }
    }

    }

    Thanks


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Having problem with factorial

    For one, I don't see where you're calculating the number's factorial.

    Also please wrap your code in [code] [/code] tags so that it retains its formatting and is easier to read.

Similar Threads

  1. [SOLVED] Sine function, can't get factorial to work
    By Actinistia in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 27th, 2012, 11:24 AM
  2. [SOLVED] Is it possible to get factorial of negative number
    By Lokesh in forum Java Theory & Questions
    Replies: 3
    Last Post: August 4th, 2011, 05:45 PM
  3. [SOLVED] Help with getting user input for my factorial method
    By u-will-neva-no in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2011, 01:24 PM
  4. Factorial and Factorion, that is the question!
    By Java Neil in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 25th, 2011, 07:54 PM
  5. [SOLVED] Factorial of 1-20
    By pitchblack in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 16th, 2011, 01:33 PM