Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Writing a recursive emthod using BigInteger

Gerald Spica
Ranch Hand
Posts: 30
I am trying to express the Recursive method

using BigInteger instead of int, when I run the code below it compiles but I get an error on line 35

Line 35 from the code below is,

from what I am able to discern from the java.math.BigInteger class this is
how this method should be declared. Can anyone help?
[CODE]
import java.io.*;
import java.math.BigInteger;

class ComputeSumApp
{
static int aNumber;
static int x = 1;
static BigInteger base = BigInteger.valueOf (x);

public static void main(String[] args) throws IOException
{
System.out.println("Enter a number: ");
aNumber = getInt();
BigInteger number = BigInteger.valueOf (aNumber);
System.out.println("Sum of the first N postitive BigInteger = " + answer);
}
public static BigInteger computeSum(BigInteger n)
{
if (n==base)
return base;
else
}
public static String getString() throws IOException
{
return s;
}
public static int getInt() throws IOException
{
String s = getString();
return Integer.parseInt(s);
}

}

Maverick Lasa
Greenhorn
Posts: 23

Hello Gerald,
The condition n==base compares the reference of the BigInteger instances and NOT their values, thus this condition is always FALSE as base and n refers to a different instances.
Try the following:

mavedrive;