That's part of the fun of computer science: learning about new (well, in this case really old) algorithms that perform a given task.
The reason why you're algorithm isn't working is because you're checking the primality of x. If you want to go about it that way, I'd recommend writing a helper function that will check to see if a number is prime, then everytime you find a prime number, print it out.
for (int i = 2; i < x; i++)
{
if(isPrime(i))
{
System.out.println(i + " is prime");
}
}
A simple primality checker:
for every integer i from 2 to the number:
if the number is divisible by i, return not prime
end
return true
There are several optimizations that you can make, the biggest being that you only have to check numbers up to the square root of the number. The second is only to check to see if the number is divisible by 2, then return false. Then, only check to see if your number is divisible by odd numbers from 3 to sqrt(number)