/    Sign up×
Community /Pin to ProfileBookmark

Can SomeOne Help me on this program

Hi,

I am trying to write a password program where application accept user password but the password character can be less than 6 charcter and not more than 10 character. After the application accept the password it will ask user to type again the password in order to match the first attempt and 2nd attempt on the password. I have write down a program but it gives me illegal expression statement error. Can someone help me please ?

public class Password {
public static void main (String [] args) {
public boolean Password( String password1, String password2 )
if(!password1.equals(password2))
return false;

if(password1.length() < 6 || password1.length() > 10 )
return false;

char[] c = password1.toCharArray();
boolean numericOk = false;
boolean letterOk = false;
for(int i=0;i<c.length;i++) {
Character char = new Character(c);
if(char.isDigit() && numericOk = false)
numericOk = true;

if(char.isLetter() && letterOk = false)
letterOk = true;

if( letterOk && numericOk )
return true;
}
return false;

}

to post a comment
Java

3 Comments(s)

Copy linkTweet thisAlerts:
@chazzyNov 21.2006 — your syntax is way off. I think you're trying to define a function inside your main?

Also, main is a void type, so you can't return anything in it.
Copy linkTweet thisAlerts:
@agent_x91Nov 22.2006 — Move the method you've made called "public boolean Password" outside of the main method. As chazzy said, you also can't return a value from the main method, so remove the line saying "return false" in your main method.

You can't define a method inside a method, so just make sure the method you have defined is [B]separate[/B] from the main method.

By the way chazzy, functions don't exist in Java. They are referred to as methods instead. ?
Copy linkTweet thisAlerts:
@chazzyNov 22.2006 — you say potato i say potato..

it's all the same stuff.

Also, the reason why you can't return anything in main isn't because it's main, but because its return type is void. You could, if you wanted, return an object of type void, but it's nearly impossible to build an object like this.

both of these methods are 100% legal.

<i>
</i>public static int main(){
return -1;
}
public static Void main(){
return null;
}
×

Success!

Help @karizmatrix spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...