| | |
Cant Solve this Java Error
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 3
Reputation:
Solved Threads: 0
I an trying to write a few java classes, which I wrote successfully, but when I am tryin to test it I get some weird errors and I cant figure out why, so i'd be very grateful for your expertise.
The code for the GCD class is:
This compiles without any problems.
The code to test the GCD class is :
When I compile it gives me the following error:
GCDTest.java:9: cannot find symbol
symbol : constructor GCD(long,long)
location: class GCD
GCD value = new GCD (x,y);
^
Here is the class for Random Prime Number Generation:
When I compile it, it works fine.
The code to test the Random Prime Number Generation class is :
It compile fine. but give me the following output instead of giving me a random prime number: RandomPrimeNos@c3c749
I hope someone can help me and tell me what I am doing wrong.
Thanks.
The code for the GCD class is:
Java Syntax (Toggle Plain Text)
public class GCD { public static long gcd(long x, long y) { while (y != 0) { long r = x % y; x = y; y = r; } return x; } }
The code to test the GCD class is :
Java Syntax (Toggle Plain Text)
import java.util.*; public class GCDTest { public static void main(String[] args) { long x = (long)(Math.random()*199)+1; long y = (long)(Math.random()*199)+1; GCD value = new GCD (x,y); System.out.println("gcd(" + x + ", " + y + ") = " + value); } }
GCDTest.java:9: cannot find symbol
symbol : constructor GCD(long,long)
location: class GCD
GCD value = new GCD (x,y);
^
Here is the class for Random Prime Number Generation:
Java Syntax (Toggle Plain Text)
import java.util.*; public class RandomPrimeNos { public static long RandomPrimeNos () { long p = (long)(Math.random()*199)+1; boolean pIsPrime = false; long i=2; while(i<=(p-1) && pIsPrime==false){ if(p%i==0){ pIsPrime=false; p = (long)(Math.random()*199)+1; i = 2; } else { i++; } if(i>=(p-1)) { pIsPrime=true; } } return (p); } }
The code to test the Random Prime Number Generation class is :
Java Syntax (Toggle Plain Text)
import java.util.*; public class RandomPrimeTest { public static void main(String[] args) { RandomPrimeNos randNum = new RandomPrimeNos (); System.out.println(randNum); } }
I hope someone can help me and tell me what I am doing wrong.
Thanks.
![]() |
Other Threads in the Java Forum
- Previous Thread: Error - Exit Timer - Please help
- Next Thread: can I make link on scroll text in a swing java
| Thread Tools | Search this Thread |
.net actuate advice ajax apple applet application array automation bc30451 binary birt blue busy_handler(null) buyouts c++ class classes code color compiler component constructor design development draw dynamic ebook eclipse eclipsedevelopment error file firefox fractal froglogic game global gnu google gui guitesting gwt html image int integer java javafx javascript jetbrains jni julia linker linux method methods microsoft mysql nameisnotdeclared netbeans newbie news nodes oop oracle oriented php platform problem programming property python rails recursion recursive return ria ruby scanner screen set software sort sorting space springsource strings subclass sun swing syntax terminal threads tree update vb vista web windows xml






