Following is ill-written code intended for judging a number is prime or not.Note that you should point out the problems first and then correct the code.
//define variables
int number;
//Create scanner
Scanner myScanner = new Scanner(System.in);
System.out.println("Please input a positive integer");
number = myScanner.nextInt();
for(int counter =1; counter < number;="">
{
if (number%counter == 0 ){
System.out.println(number+" is NOT prime!");
}
else{
System.out.println(number+" is prime!");
break;
}//end for
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here