Please help!

R

RedGrittyBrick

emilie wrote:

<snip: source code for program to calculate Greatest Common Divisor of
two integers using the Euclidian algorithm>
actually, my assignment is just to fill up some missing informations.

You posted this identical message to a half dozen reponses in this
thread. That means I have read this exact same text many times over.
Try to imagine the effect that has on how people feel about helping you.
the only problem with my code is the console.readInt. Everytime i
compile it, an error appears regarding it..thanks!

To get the best out of newsgroups I find I need to be specific. Exactly
what error message did you get? Using cut & paste prevents typing errors
and saves time.

You might like to read some guidelines on getting the best out of
newsgroups ...
http://www.catb.org/~esr/faqs/smart-questions.html



I loaded your original code into Eclipse and it said "Console cannot be
resolved" at this line:
int x = Console.readInt();
I looked up the Javadocs for Console at
http://java.sun.com/javase/6/docs/api/java/io/Console.html
and noted that it says "Since: 1.6".

I am using 1.5. That explains that error I guess.

I therefore changed the start of the program as follows
public static void main(String[] args) throws IOException {
InputStreamReader stdin = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(stdin);
String s = console.readLine();
int x = Integer.parseInt(s);

Ditto for y.


Eclipse said "The constructor GCDSolver(int, int) is undefined" at this
line:
GCDSolver solver = new GCDSolver(x, y);
So I changed
public void GCDsolver(int a, int b){
to
GCDSolver(int a, int b){
(Note the capital S)

After that it worked.

Merry Xmas!
 
J

John Ersatznom

Mark said:
I believe the crypto routines use a different "secure" random number
generator. The regular use, random number generators are always a
compromise between quality and performance. I think the java.util.Random
implementation is a reasonable one in this context.

MT isn't exactly slow, you know.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

John said:
MT isn't exactly slow, you know.

True.

But it was invented 2 years after Java 1.0 was released.

And since the java docs explicit specifies the algorithm, then
it would have been a problem to change it.

They could have added a new one later, but it has apparently
not been prioritized.

Arne
 
D

Daniel Dyer

MT isn't exactly slow, you know.

To put some figures on this, the Java port of the Mersenne Twister that I
use for my Watchmaker project is about 20% quicker than java.util.Random
and, unlike java.util.Random, the Diehard tests do not flag any issues
with the output.

Dan.
 
D

Daniel Dyer

But it was invented 2 years after Java 1.0 was released.

And since the java docs explicit specifies the algorithm, then
it would have been a problem to change it.

They could have added a new one later, but it has apparently
not been prioritized.

Arne

Unfortunately, the initial implementation was flawed and, for the reasons
you highlight, we are stuck with it.

From Roedy Green's page on pseudorandom numbers
(http://mindprod.com/jgloss/pseudorandom.html):

"Unfortunately, even if you do everything perfectly to use
java.util.Random, the generator itself is flawed. It falls into the trap
Knuth says to avoid — using a power of two for the modulus. The random
numbers it generates are not all that random. It is blindingly obvious
when you plot the low order bits of the random numbers visually."

Dan.
 
J

jupiter

Oliver Wong said:
emilie said:
I'm a beginner in java..this is actually my second program in
java..can
you help me with my code?? pleeaaassee??
[code snipped]

Yes, we can probably help you. What are you having difficulty
with?

- Oliver

actually, my assignment is just to fill up some missing
informations.
the only problem with my code is the console.readInt. Everytime i
compile it, an error appears regarding it..thanks!
 
J

John Ersatznom

Mark said:
Isn't a little slow to initialise or am I thinking of something else?

Fortunately, initialization isn't usually the first place you go looking
for a performance hotspot. In fact, there's three major areas were
random numbers are used extensively:
1. Security/crypto apps and 2. games -- I/O wait times dominate both fields
3. Mathematics (simulations, monte carlo integration...) -- crunching
speed becomes important, but it's calls to the next() method in
innermost loops that will predominate over constructing new instances on
far rarer occasions, or possibly even only once.
 
O

Oliver Wong

jupiter said:
Oliver Wong said:
emilie said:
I'm a beginner in java..this is actually my second program in java..can
you help me with my code?? pleeaaassee??
[code snipped]

Yes, we can probably help you. What are you having difficulty with?

actually, my assignment is just to fill up some missing informations.
the only problem with my code is the console.readInt. Everytime i
compile it, an error appears regarding it..thanks!

It might be easier to help you if you stated the error message.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top