Help pls...

help pls. i'm writing a program that takes user input for a password and and uses a method to checks make sure 1) it is at least 8 characters long, 2) is composed of only letters and digits, and 3) contains at least 2 digits. my compiler keeps saying error: class, interface or enum expected.

post the fucking code, dickhead, or at least tell us which language you're using

import java.util.Scanner;

public class Exercise
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

System.out.println("Please enter your passcode: ");

String password = input.next();

if (theJudge(password) == true)
{
System.out.println("Valid Password");
}

else
{
System.out.println("Invalid Password");
}
}
}

public static boolean theJudge(String s)
{
boolean result;

int length = s.length();

if(length < 8 )
{
result = false;
return result;
}

int digitCount = 0;

for(int i = 0; i < length; i++)
{
char character = s.charAt(i);

if ( isLetter(character) == true)
{
continue;
}

else if ( isDigit(character) == true)
{
digitCount++;
continue;
}

else
{
result = false;
return result;
}
}

if(digitCount < 3)
{
result = false;
return result;
}

else
{
result = true;
return result;
}
}

it wouldn't all fit so i had to cut it down

Bump

what program are you using, doesnt it say what line the error occurs

its a java program and i'm using texpad. not sure what compiler but i can find out. it gives me

java:25: error: class, interface, or enum expected
public static boolean theJudge(String s)

sorry, yes it is line 25; the method header for theJudge()

>java:25:
thats probably line25

but what do I know, I use a proper IDE

Yes I believe you are correct. Can you try compiling it on yours and tell me what it says?

you need to remove the trailing bracket from your first post and move it to the end of this post

theJudge isnt inside a class, using proper alignment in notepad it should align in the same column as "public static void main"

kek i think its because i defined the method outside of the main method derp

yes i believe you are absolutely correct, thank you

Just use a regular expression to check against it.

hmmm... now its giving me an error saying it doesn't know what " isLetter(character)" is

its several lines into theJudge() method,

for(int i = 0; i < length; i++)
{
char character = s.charAt(i);

if ( isLetter(character) == true)
{
continue;
}

You can do that all with one single regex expression...

nevermind i figured it out. i needed to retrieve it from the library using the dot operator, so it sould be

if ( Character.isLetter(character) == true)

Use a regex, keep it simple. Something like:

^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\S+$).{8,}$

idk what regex is

this is for a progamming 2 course, though this assignment in particular is supposed to give us a refresher on material we should have mastered from programming 1

i'm afraid this is quite foreign to me

rational expression, defining search patterns

or just

if( Character.isLetter(character) ) {
// do stuff
}

This works because the expression "something == true" will return true or false itself, so the "== true" is redundant, because you are asking if true == true

Just read the Java docs on it.

I will investigate this, thank you. I have to go eat now. thank you everyone.

i dont know if you can tell but this is an introduction to programming course

So you're just going to just do the bare minimum? Typical SJW

yep programming isnt important in this world, soon it will be automated like everything else