Sunday, September 30, 2012

Project Euler Problem 13 (continued)

Alhamdulillah, got it. It is kind of cheating of me, because I used Java this time. Using BigInteger, Scanner and File classes, that was almost easy. I did stumbled a bit, but a lot easier than making C++ one.

I used Scanner & File for file input. Then, utilizing the simple to use BigInteger to create array that will store input. BigInteger is another class, so I required a special method add() to add the BigInteger later. Sum of type BigInteger to be sum counter. But, BigInteger is immutable, so I have to re-initalize it.

sum = sum.add(array[i]);

Then display only the first 10 digits. Change first to string with ever-popular toString()substring(0,10) is used that way so it will start from the beginning until index (10-1), or in other word, first 10 characters.

 
"input.dat"

Saturday, September 29, 2012

Making my own simple ArrayList class

Peace be upon you. Been a very long time since I post. :P

Anyway, I am currently studying Intelligent System. One of the courses make me programming Java again. Interestingly, we actually create our own simple ArrayList class. It is not complete class, but it is kind of interesting. Few days ago we learn concept of building LinkedList. So um, here is the lab for ArrayList code.

Oh and I used BlueJ. Nice. I don't need to type into command prompt anymore. This is important because I started a habit of using Scanner.