Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 BigInteger
Index -> Programming, Java -> Java Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cool dude




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: 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.
cool dude




PostPosted: 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?
wtd




PostPosted: 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.
cool dude




PostPosted: 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?
wtd




PostPosted: 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.
cool dude




PostPosted: 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?
cool dude




PostPosted: Sat Jun 17, 2006 2:45 pm   Post subject: (No subject)

oh and how do u convert from a BigInteger to String
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: 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.
cool dude




PostPosted: 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 Confused

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);
        }
}
wtd




PostPosted: Sat Jun 17, 2006 3:36 pm   Post subject: (No subject)

Read the error message. Think about the problem.
cool dude




PostPosted: 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.
wtd




PostPosted: Sun Jun 18, 2006 10:31 am   Post subject: (No subject)

So it outputs nothing, you're saying?
cool dude




PostPosted: 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.
wtd




PostPosted: Sun Jun 18, 2006 10:55 am   Post subject: (No subject)

What does it say?

(one step at a time...)
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: