Question:
Java error "Not a statement"?
Thomas
2013-04-21 16:33:34 UTC
I'm new to java and I'm having some trouble. I keep getting two errors on this, Not a statement and ";" expected.
Also if there is other stuff wrong please let me know. =D

This is the part with the error int for(int i=0; i >= 8; i++)
here is the whole thing

import java.util.Scanner;
public class CurranThomasProg5
{
public static void main(String args[])
{ Scanner input = new Scanner(System.in);
System.out.println("Password Verifier\n");
System.out.println("Enter a password that meets the following rules:");
System.out.println("Is at least 8 characters long.");
System.out.println("Contains atleast 1 lower letter character ");
System.out.println("Contains atleast 1 upper letter character ");
System.out.println("Contains atleast 1 numeric digit");
System.out.println("Contains atleast 1 special character from the set: !@#$%^&*");
System.out.println("Does not contain the word \"and\" or the word \"end\"");
String pw = input.nextLine();
boolean oneLower = false; boolean oneUpper = false;
boolean oneNumber = false;
boolean oneSpecial = false;
boolean noAnd = false;
boolean noEnd = false;
int for(int i=0; i >= 8; i++)
{
char c = pw.charAt(i);
if(Character.isLowerCase(c)) oneLower = true;
if(Character.isUpperCase(c)) oneUpper = true;
if(Character.isDigit(c)) oneNumber = true;
if(c == '!' || c=='@' || c=='#' || c=='$' || c=='%' || c=='^' || c=='&' || c=='*') oneSpecial = true;
}
if (pw.indexOf("and") > 0) noAnd = true;
if (pw.indexOf("end") > 0) noEnd = true;
if(oneLower && oneUpper && oneNumber && oneSpecial && noAnd && noEnd && length)
{
System.out.println("Valid");
}
else if (!oneLower)
{
System.out.println("Invalid" + "\n" + "Must contain at least one lowercase character");
}
else if (!oneUpper)
{
System.out.println("Invalid" + "\n" + "Must contain at least one uppercase character");
}
else if (!oneNumber)
{
System.out.println("Invalid" + "\n" + "Must contain at least one digit");
}
else if (!noAnd)
{
System.out.println("Invalid" + "\n" + "Contains the string \"and\"");
}
else if (!oneSpecial)
{
System.out.println("Invalid" + "\n" + "Missing a special character");
}
else if (!noEnd)
{
System.out.println("Invalid" + "\n" + "Contains the string \"end\"");
}
else if (pw.length() < 8)
{
System.out.println("Invalid" + "\n" + "Must contain at least 8 characters");
}
}
}
Five answers:
?
2013-04-21 16:45:25 UTC
Remove the "int" at the beginning:



int for(int i=0; i >= 8; i++)

^there



Also, "length" is undeclared or undefined at this line:

if(oneLower && oneUpper && oneNumber && oneSpecial && noAnd && noEnd && length) <


So declared "length" as integer, not a boolean because you want to test if the length is greater or equal to 8.



Edit: Yes, guy below me thanks I forgot to mention about the "for" boolean expression. The for loop will never execute because of "i >= 8". You set "i" to 0 at "int i=0" and "i" is not greater than 8 so it will not run. So the correction is:

i <= 8;
morriss
2016-12-30 08:11:43 UTC
Java Not A Statement
?
2016-10-14 05:04:53 UTC
Not A Statement Java
elden w
2013-04-21 17:36:28 UTC
Thomas,



In this code "int for(int i=0; i >= 8; i++)" even if it is correct it will not start because it says "starting at zero to i is greater than or equal to 8 incrementing by 1, do something, so the i++ makes the zero a 1 but that is not greater than or equal to 8 so nothing will happen.



Try <=8 and it may work.
Wendy
2016-04-11 01:12:00 UTC
For the best answers, search on this site https://shorturl.im/avuZ8



if (answerone == 2); <--- Remove semicolon here, it ends the if statement.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...