Erandika Withanage

Greenhorn
+ Follow
since Apr 08, 2011
Erandika likes ...
Android Eclipse IDE Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Erandika Withanage

This is what I tried:

Hi! I'm doing K&B6.

I've got a small prob with enums in the first chapter. Could someone please help me out:)?

In the example in pg.63-64, the enum is declared outside the class and this enhanced for loop works fine.



What about when the enum is declared inside a class? How do you declare the above for loop to do the same thing? I've tried different ways, but something is wrong all the time.

Please help and thank you in advance:)
Thank you:). It works perfectly now.

Just wondering about the underlying reason?

Seems there's no escaping the good ole' command line.
I want to get the name of the thread running the main() method and my code is as follows.



When execured, what I get is:



I don't get this. According to K&B the thread name should be 'main'? Is it a problem with my settings or IDE (DrJava)?
Just a small question here: when the book says connecting characters, what other than the underscore "_" can be used as an underscore?

I've tried dash "-" and it gives an error.
Hi!
How is this study group going?
I'd like to join in too. I'm currently studying from K&B and hope to the the exam by the end of August or early September.
Badly want a study partner/group to keep up my motivation!

Campbell Ritchie wrote:Where did it say that buffered readers and tokenizers were quicker? How old was that reference? Have you tested it? How do you know it is accurate?

You need to be circumspect about weird things you find on the net. Here, too, though we usually find errors quite quickly!



http://www.cpe.ku.ac.th/~jim/java-io.html

11 years ago

Junilu Lacar wrote:

Erandika Gun wrote:I am learning to code through Algorithm contests which requires speed over ease.


So if you win something from advice you get here, will you donate a portion of your winnings to us, to be used towards the upkeep of the site?

Speed over ease, huh... so the idea is to buy now and pay later, too?



There's no winnings, they are just student competitions:p... But sure, if I ever get so good...;). I'm asking for advice within the competition limits, as its only input/output questions I ask and not strategy.

The code should compile within the given time limit and using the Scanner class slows it down. I read that BufferedReader and StringTokenizer are faster and came up with these problems.

Anyway, thank you all for your kind help:).
11 years ago

Campbell Ritchie wrote:

Erandika Gun wrote:. . . I am learning to code through Algorithm contests which requires speed over ease.

Do you really mean “learning”?



Not actually the basics, but the more salient points:).
11 years ago

Campbell Ritchie wrote:

Erandika Gun wrote:. . . I used a BufferedReader and StringTokenizer for this. . . .

Why? A tokenizer is legacy code, which you ought not to use in new code. Why are you not using something like Scanner instead, which will find the next int directly.



The Scanner class is slow. I am learning to code through Algorithm contests which requires speed over ease.
11 years ago
The declared variables are already given, so is there need for a hasmoreTokens()?

I tried this code with split() too and it doesn't work:s.
11 years ago
I am writing a code that involves reading two space separated integers from standard input.

I used a BufferedReader and StringTokenizer for this.

My code is as follows.




And this throws an Exception as follows for the line

Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(Unknown Source)
at le.main(le.java:20)

I really can't figure out what I'm doing wrong. Can someone help me put please???
11 years ago

Paul Clapham wrote:Perhaps you didn't wait long enough? It could take quite a while to figure out if 600 billion numbers are factors of that number, which is what you would be doing if it were prime.

By the way let me point out that the smallest non-trivial divisor of any number must be prime. You don't need to do that check.



It gives out the individual results very quickly, so can it be a problem with speed?

I am a bit confused with what you meant by smallest non trivial divisor of a number. Could you explain it a bit more?
12 years ago
I'm a newbie programmer and I've been solving Project Euler problems.

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?





My problem is that if I put the following it does not give any result. In the previous code, it printed out all the prime factors and I put the last one as the answer as the maximum prime factor. I want to make a code that only gave the maximum, but if I used the following, there's no output at all. Where did I go wrong and what should I do?




Please help!Thank you in advance!
12 years ago