how to write code in java this statm if

public  String pass (){
        b =txt_pass.getText(); 
        if ("ameer".equals(b)) 
            JOptionPane.showMessageDialog(null, "the password is correct");
        return b;
         }

how to make this

 **if (user ()) retrun a **
 JOptionPane.showMessageDialog(null, "the password is correct");

Recommended Answers

How about returning a boolean?

// pseudo-code!
public boolean passwordIsOK() {
    get the password
    if (the password is correct) return true;
    else return false;
}

then you can say

if (passwordIsOK()) ... do whatever
Jump to Post

All 2 Replies

How about returning a boolean?

// pseudo-code!
public boolean passwordIsOK() {
    get the password
    if (the password is correct) return true;
    else return false;
}

then you can say

if (passwordIsOK()) ... do whatever

or, simplified:

get the password;
return (if the password is correct);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.