I need to use a nested for loop to get a list of prime numbers, here is the code:
public static void main(String[] args) {
for (int i = 2; i <= 10; i++)
{
for (int d = 3; d <= 10; d = d + 2)
{
int result = d % i;
System.out.println(result);
}
}
}
I think I have the logic right here, but the results was a bit out of mind, any suggestions please ?
What you are doing is only a bit related to finding out prime numbers in that, you are using
modulusoperator, that is needed, but nothing more than that.You actually need to make use of the result of that operation.
You can follow the following
pseudo-code: –I am not giving away the code, since it would be beneficial for you to try it out on your own. You will learn how to implement a problem statement given in the form of algorithmic steps.