Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:08:28+00:00 2026-06-17T13:08:28+00:00

I need help on how to return a boolean method in java. This is

  • 0

I need help on how to return a boolean method in java. This is the sample code:

public boolean verifyPwd(){
        if (!(pword.equals(pwdRetypePwd.getText()))){
                  txtaError.setEditable(true);
                  txtaError.setText("*Password didn't match!");
                  txtaError.setForeground(Color.red);
                  txtaError.setEditable(false);
           }
        else {
            addNewUser();
        }
        return //what?
}

I want the verifyPwd() to return a value on either true or false whenever I want to call that method. I want to call that method like this:

if (verifyPwd()==true){
    //do task
}
else {
    //do task
}

How to set the value for that method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:08:29+00:00Added an answer on June 17, 2026 at 1:08 pm

    You’re allowed to have more than one return statement, so it’s legal to write

    if (some_condition) {
      return true;
    }
    return false;
    

    It’s also unnecessary to compare boolean values to true or false, so you can write

    if (verifyPwd())  {
      // do_task
    }
    

    Edit: Sometimes you can’t return early because there’s more work to be done. In that case you can declare a boolean variable and set it appropriately inside the conditional blocks.

    boolean success = true;
    
    if (some_condition) {
      // Handle the condition.
      success = false;
    } else if (some_other_condition) {
      // Handle the other condition.
      success = false;
    }
    if (another_condition) {
      // Handle the third condition.
    }
    
    // Do some more critical things.
    
    return success;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to override this method and stuck with some problem public boolean onKeyDown(int
I need help understanding whats going on in the function, especially the return statements.
Hi i need help with my input file: checkdata.py return with No errors but
I need help with creating a C# method that returns the index of the
Need help writing a script downloads data from google insight using c# this is
This is for a tic tac toe game. I need help making a check
Is this how to properly call a method from another method in java? Can
My code is here: public static boolean showConfirmationDialog(Context context, String title, String dialogContent) {
When I run this code, it shows error. Please, help me out. I'm trying
I need to create a recursive Boolean method named isMemeber. The method should accept

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.