afaik its not homework and i purposly didn't made clean code so he can figureout how to do the for loop and whatever he wants to do with it.I'm sure it can be done more elegantly than thisbutthats up to you.Beautiful. Just f'n beautiful.
This teaches the OP how to go sparrow hunting with an
Uzi. Nuthin left but feathers.
...There is no need for such a disclaimer/header because AFAIK, what you just posted is no intellectual property of yours. You only demonstrated the use of some standard Java classes. Nothing more.
// Copyright Information:
// Copyright (C) 2007 <Institution><None>
// Ark de Appel www.engineeringserver.com
//
//----------------------------------------------------
------------------*/
import java.math.BigInteger;Why did you choose the number 10 in isProbablePrime(10)?
class Sun_Algho {
public static void main(String [] args){
int isPrime = 137;
int result = 0;
int i = 1;
System.out.println("Test Prime: ");
for (int j = 0; j < 100; j++){
BigInteger bigInt = BigInteger.valueOf(j);
if(bigInt.isProbablePrime(10)){
...What is this test #2? If you change isPrime to composite number, it'll be marked as a prime number!
System.out.println("Test# 2");
if (isPrime%i == 0){
result++;
}
if (result <=2){
System.out.println("Prime: " + isPrime + " is
is Prime? Yes ");
}
else{
System.out.println("Prime: " + isPrime + " is
is Prime? No ");
...
...Sticking some lines of code in one (main) method is not helping the OP at all, IMHO.
afaik its not homework and i purposly didn't made
clean code so he can figureout how to do the for loop
and whatever he wants to do with it.
i don't see a problem with this.I do.
Its a template i use in eclipe for any new class thatYes, I figured that much. What I mean is you don't need to post it here if you're posting some lines of code.
i make.
Anyway i'll look into that. I probably forgot a check
somewhere.
Looking at my code again I suppose i could create a method for it and split the code so its easier to read and understand....loop
afaik its not homework and i purposly didn't made
clean code so he can figureout how to do the forand whatever he wants to do with it.Sticking some lines of code in one (main) method is
not helping the OP at all, IMHO.
i don't see a problem with this.I do.
I totally agree on that. i'll work on my posting skill in my future posts :)Its a template i use in eclipe for any new classthati make.check
Anyway i'll look into that. I probably forgot asomewhere.Yes, I figured that much. What I mean is you don't
need to post it here if you're posting some lines of
code.
...Thank you for your consideration.
I totally agree on that. i'll work on my posting
skill in my future posts :)
AFAIK, the bigger the argument in the isProbablyPrime method, the greater the accuracy, but the slower the calculation. But the OP doesn't need obscure approximation methods for calculating primes, the OP needs a precise simple algorithm. I liken the above to sparrow hunting w/ an uzi. Sure he can kill birds with it, but with what result? What useful information does he gain?if(bigInt.isProbablePrime(10)){Why did you choose the number 10 in
isProbablePrime(10)?
Yes, I know. I was more interested in the motivation of the author of that code as to why s/he choose the number 10....AFAIK, the bigger the argument in the isProbablyPrime
Why did you choose the number 10 in
isProbablePrime(10)?
method, the greater the accuracy, but the slower the
calculation. ...
But the OP doesn't need obscureProbably none.
approximation methods for calculating primes, the OP
needs a precise simple algorithm. I liken the above
to sparrow hunting w/ an uzi. Sure he can kill birds
with it, but with what result? What useful
information does he gain?
to print prime elements between zero and 25Then my suggestion is the following:
for (int i = 0; i < 26; i++) {
if (isPrime(i)) {
System.out.println("A prime: " + i);
}
}
Much clearer, don't you think? (It also seperates the showing of the result from your 'prime-determining-code' which allows you to focus better.)