What's wrong with my code? Are there any errors? Is the idea right? Please helpThanks

//I want to know if this program is right. The program uses loops to find the first 400 primes.

class Primes {

public static void main(String[] arguments) {

int counTer2 = 0;

primeLoop:

while (counTer2 < 401) {

for (int prime = 2; prime<prime+1; prime++) {

for (int number = 1;number <prime+1; number++) {

int counter = 0

if (prime%number == 0)

counter = counter + 1;

}

if (counter == 2)

System.out.println("#:" + prime);

counTer2 = counTer2 + 1;

}

if (counter2 == 401)

break primeLoop;

}

}

}

Re: What's wrong with my code? Are there any errors? Is the idea right? Please helpTh

Quote:

Originally Posted by

**Chris511026**
//I want to know if this program is right.

Does the code compile? Is the output that which you would expect?

As a side note, consider using code tags when posting your code as this makes it much easier to read. For instance:

Code java:

class Primes {
public static void main(String[] arguments) {
int counTer2 = 0;
primeLoop:
while (counTer2 < 401) {
for (int prime = 2; prime<prime+1; prime++) {
for (int number = 1;number <prime+1; number++) {
int counter = 0
if (prime%number == 0)
counter = counter + 1;
}
if (counter == 2)
System.out.println("#:" + prime);
counTer2 = counTer2 + 1;
}
if (counter2 == 401)
break primeLoop;
}
}
}

To use these, you would wrap your code with these tags: [code=java] [/code]

Re: What's wrong with my code? Are there any errors? Is the idea right? Please helpTh