| | |
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 6 ajax apple applet application array automation bank bi binary blue bsod business businessintelligence c# c++ chat class classes code commonfunctions compiler component convert derby design development dns draw eclipse email error ext file firefox fractal game google grails gui gxt html hyper image innodb int integer java javafx javascript jetbrains jni julia linker linux main method methods microsoft microsystems mysql netbeans newbie noob object oop osx php printf problem programming python qt recursion rodjohnson ruby scanner screen security set software sort sortedmaps sql string sun superclass swing syntax threads title transform tree ubuntu update vista web windows xsl






