Im bad at Java oof
Warhawk947 (340)

A project I made for school.

How did this get so many upvotes thanks guys

cheers, warhawk947

You are viewing a single comment. View All
Highwayman (1049)

Uh. So. I entered 0.
...

Ok.

Yeah.

Warhawk947 (340)

@Highwayman yeah if you enter a number smaller or equal to 0 it will print infinite primes

MatthewDoan1 (312)

@Warhawk947 Instead of using a while loop, you should check out the for loop: w3schools

Warhawk947 (340)

@MatthewDoan1 thanks for the tip, however here I need a while loop because i'm printing a number of primes, not a number of numbers. If I was printing all the numbers from one to ten, i could use a for loop, but i need to print a number of primes, so i need to use a while loop.

MatthewDoan1 (312)

@Warhawk947

for(int currPrime = 2; currPrime < num; currPrime++)
{

// Insert rest of code here

}
Warhawk947 (340)

@MatthewDoan1 no I'm not doing prime numbers up to a number, I'm doing a number amount of prime numbers (for example if I enter 10 in the project, it won't print out 2, 3, 5, 7. It will print out 2, 3, 5, 7, 11, 13, 17, 23, 29)

Highwayman (1049)

@Warhawk947
C++ example because I’m too lazy rn.

for(int i = 0,num_to_check = 2;i < primes_numbers_to_gen;num_to_check++){
  if(isPrime(num_to_check)){
    std::cout << num_to_check;
    i++;
  }
}

This just goes to show that this probably isn’t)t the best idea.
Just my opinion.

Warhawk947 (340)

@Highwayman idk if you can do that in java, but you have a point. Thanks!

Warhawk947 (340)

@Highwayman no i'm serious. I didn't know you could do that in java

Warhawk947 (340)

@Highwayman only increase the counter variable in a loop if a condition is true

Highwayman (1049)

@Warhawk947 oh! Welp. Now you know lol. 😜

MatthewDoan1 (312)

@Warhawk947

for (int primesPrinted = 0; primesPrinted < num;)
{
    if (xyz)
    {
        primesPrinted++;
    }
}