According to Wikipedia's Java Version Page, this program would have been created for Java 1.2. The program took a number, computed all the primes to that number, and could print out the calculated primes or number of primes.
import java.util.*;
public class prime3b
{
public static void main(String [] args)
{System.out.print("Would you like to print out all the primes?");
String cond = KeyBoard.readString();
boolean f = true;
boolean d = true;
if (cond == "no")
{f = !f;
}
System.out.print("Would you like to print out the number of primes?");
cond = KeyBoard.readString();
if (cond == "no")
{d = !d;
}
System.out.print("Enter a number:");
int x = KeyBoard.readInt();
int a = 0;
int b = 0;
int []m = new int [100000];
m[0] = 2;
int z = 0;
int e = 0;
int c = 3;
int y = 0;
long t1 = (new Date()).getTime();
for(; c <= x; c = c + 2)
{y = (int) Math.sqrt(c);
for(z = 0; m[z] <= y; z++)
{a = c % m[z];
if (a == 0)
{b = 1;
}
}
if (b == 0)
{e++;
m[e] = c;
}
else
{b = 0;
}
}
long t2 = (new Date()).getTime();
t2 = t2 - t1;
z = e;
if (f == true)
{for (; z != -1; z--)
{System.out.println(m[z]);
}
}
if (d == true)
{e++;
System.out.println("There were " + e + " primes at or below " + x);
}
System.out.println("Time is:" + t2);
}
}
PS In case you're wondering about my instructor's feedback, he said that one day I would be a superb programmer, after I had been crushed by the complexity of a few systems (I don't think he said "been crushed by", maybe "grappled with?"). This would teach me discipline, actions like encapsulating code into functions, thinking about testing, using standard formatting, using better variable naming, checking inputs, checking boundary conditions, and learning that code was also meant for people.
I'm still hoping his prediction comes true.
PPS I think most programmers fall into two categories: OCD programmers who need everything perfect, constantly re-visiting and re-working, or
3 comments:
Happy Birthday Matt.
Jenn's Dad.
Thinkin of you! Hope everything is well back in ze Nether lands. :)
you are so not old!
Happy Birthday Pud-Butt!
Post a Comment