Author |
Message |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sat Jun 17, 2006 10:19 am Post subject: BigInteger |
|
|
i just learned BigInteger but i'm having a small problem.
code: |
import java.math.BigInteger;
public class Problem20 {
public static void main (String[] args){
BigInteger n = BigInteger.valueOf(100);
BigInteger total = BigInteger.valueOf(100);
for (int i = 1; i <= 99; i++){
total = total.multiply(BigInteger.valueOf(n.subtract(BigInteger.valueOf(i))));
}
System.out.println(total);
}
} |
it says that cannot resolve symbol method valueOf(java.math.BigInteger) on line 8 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sat Jun 17, 2006 10:22 am Post subject: (No subject) |
|
|
The error is telling you there's no valueOf method that takes a BigInteger as an argument. |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sat Jun 17, 2006 10:36 am Post subject: (No subject) |
|
|
wtd wrote: The error is telling you there's no valueOf method that takes a BigInteger as an argument.
wat does that mean? |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sat Jun 17, 2006 11:04 am Post subject: (No subject) |
|
|
Look at the BigInteger API docs. Tell me what kind of arguments valueOf can take. |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sat Jun 17, 2006 2:26 pm Post subject: (No subject) |
|
|
wtd wrote: Look at the BigInteger API docs. Tell me what kind of arguments valueOf can take.
isn't it Integers. thats wat it looks like when i look on the internet. they plug in a number (integer) inside the brackets. am i right? |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sat Jun 17, 2006 2:30 pm Post subject: (No subject) |
|
|
/me sighs
code: | static BigInteger valueOf(long val) |
It takes a "long" value, not a BigInteger object. |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sat Jun 17, 2006 2:39 pm Post subject: (No subject) |
|
|
ya i just figured it out a sec ago. i fixed it up, but i still have a question. if u did need a bigInteger value there instead of the long is there any way to have it? |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sat Jun 17, 2006 2:45 pm Post subject: (No subject) |
|
|
oh and how do u convert from a BigInteger to String |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sat Jun 17, 2006 2:45 pm Post subject: (No subject) |
|
|
Look at the methods that are available for BigInteger objects.
You really need to learn how to read the API docs. That skill will be the key to either sinking or swimming with Java. |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sat Jun 17, 2006 3:31 pm Post subject: (No subject) |
|
|
i figured it out, but now when i'm adding all the digits in the number up i'm getting an error and i have no idea why
code: |
import java.math.BigInteger;
public class Problem20 {
public static void main (String[] args){
int n = 100;
int sum = 0;
BigInteger total = BigInteger.valueOf(100);
for (int i = 1; i <= 99; i++){
total = total.multiply(BigInteger.valueOf(n - i));
}
String stotal = total.toString();
int k = stotal.length();
for(int j = 1; j <= k; j++){
sum = sum + Integer.parseInt(stotal.substring(j,1));
}
System.out.println(sum);
}
} |
|
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sat Jun 17, 2006 3:36 pm Post subject: (No subject) |
|
|
Read the error message. Think about the problem. |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sun Jun 18, 2006 10:27 am Post subject: (No subject) |
|
|
wtd wrote: Read the error message. Think about the problem.
they don't really give me an error message. usually when there's a problem i'm given an error message and shown the line number with the error. this time though it compiles and doesn't show any error message, but when i try to run it it doesn't run. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sun Jun 18, 2006 10:31 am Post subject: (No subject) |
|
|
So it outputs nothing, you're saying? |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Sun Jun 18, 2006 10:40 am Post subject: (No subject) |
|
|
wtd wrote: So it outputs nothing, you're saying?
Not exactly. when i compile it, usually it tells me there is an error but it doesn't. when i run it it says something but i have no clue wat it means. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Sun Jun 18, 2006 10:55 am Post subject: (No subject) |
|
|
What does it say?
(one step at a time...) |
|
|
|
|
![](images/spacer.gif) |
|