Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:21:48+00:00 2026-05-17T00:21:48+00:00

This is oddly my first Java application, I was wanting to implement an arbitrary

  • 0

This is oddly my first Java application, I was wanting to implement an arbitrary precision factorial function, I did the recursive one fine but my iterative one simply outputs “1” and nothing else.. It is so late for me I can not spot why, I am not sure where I went wrong, is there something obvious here?

public static BigInteger ifact(BigInteger n) {
    BigInteger ret = new BigInteger("1");
    BigInteger i = new BigInteger("1");
    for(i = new BigInteger("0"); i.compareTo(n) == 0; i.add(new BigInteger("1"))){
        ret.multiply(i);
    }
    return ret;
}

In case you did not notice it uses the BigInteger package, hense the odd writings..

Also, like C, can you do something similar to typedef so I don’t need to type “BigInteger” each time?

EDIT: I think I meant to set ret as n, that may be it, or..maybe not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:21:49+00:00Added an answer on May 17, 2026 at 12:21 am

    In answer to your “typedef” question, no, you can’t do that in Java.

    As for your code, it has numerous mistakes. Your loop will only ever execute once, and only if n is equal to i. Why do you initialize i to 1 and then 0 at the beginning of the loop? Why do you ignore the result of i.add(...)? Why do you ignore the result of ret.multiply(i)? Remember, these methods don’t change the BI itself!

    This incorporates those changes:

        BigInteger n = BigInteger.valueOf(10);
        BigInteger ret = BigInteger.ONE;
        for (BigInteger i = BigInteger.ONE; i.compareTo(n) <= 0; i = i.add(BigInteger.ONE)) {
            ret = ret.multiply(i);
        }
        System.out.println(ret);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might seem phrased oddly at first, but let me explain through example. Note
(I know this is a sort of lazy question, but it's oddly hard to
this is my first question in here, and I would like to ask if
This should be a simple one: I have an observableArray object called To in
This works. $(document).ready(function(){ $(.items article).click(function(){ window.location=$(this).find(a).attr(href); return false; }); }); However , when the
Oddly enough, most of this works as it has been written, however I'm not
....maybe not so simple. First, I am trying to code this in Wordpress, not
My C# application calls a function in a C++ DLL at run-time and throws
My question is similar to this one , but more complicated. I am trying
I have two problems. The first one is that I'm using JSP and that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.